forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyperapp.test.js
43 lines (37 loc) · 1.08 KB
/
hyperapp.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/** @jsx hyperapp.h */
import 'jest-dom/extend-expect'
import * as hyperapp from 'hyperapp'
import {getQueriesForElement, wait} from 'dom-testing-library'
import {fireEventAsync} from './fire-event-async'
export const state = {count: 0}
export const actions = {
increment: value => state => ({count: state.count + value}),
}
export const view = (state, actions) => (
<div>
<button onclick={() => actions.increment(1)}>{state.count}</button>
</div>
)
async function render({
state,
view,
actions,
container = document.createElement('div'),
}) {
hyperapp.app(state, actions, view, container)
await wait() // hyperapp renders on the next tick
return {
container,
...getQueriesForElement(container),
}
}
// export {render}
// export * from 'dom-testing-library'
test('renders a counter', async () => {
const {getByText, getByTestId} = await render({state, view, actions})
const counter = getByText('0')
await fireEventAsync.click(counter)
expect(counter).toHaveTextContent('1')
await fireEventAsync.click(counter)
expect(counter).toHaveTextContent('2')
})