Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created June 6, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmccray/9253ef1fe8c3fccc025543486bbd7b12 to your computer and use it in GitHub Desktop.
Save mattmccray/9253ef1fe8c3fccc025543486bbd7b12 to your computer and use it in GitHub Desktop.
Single-File React Component - Example (idea)
<script role="view">
import { store, view } from 'react-easy-state'
const counter = store({
value: 0,
increment() { counter.value += 1 },
decrement() { counter.value -= 1 }
})
export default view(() => (
<div className="Test">
<p>Count: {counter.value}</p>
<p>
<button onClick={counter.increment}>+</button>
<button onClick={counter.decrement}>-</button>
</p>
</div>
))
</script>
<style>
.Test {
font-size: 120%;
}
</style>
<script role="test">
import test from 'test'
test('Test component', it => {
it("Renders a count", expect => {
const output = render(<Test/>)
expect(output).toHaveText("Count: 0")
})
it("Increments count", async expect => {
const output = render(<Test/>)
const btn = find('button', {text:'+'})
await btn.click()
expect(output).toHaveText("Count: 1")
})
})
</script>
<script role="story">
export const Standard = () => (
<Test />
)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment