forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyperapp.test.js
44 lines (37 loc) · 1.07 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
44
/** @jsx hyperapp.h */
import '@testing-library/jest-dom/extend-expect'
import * as hyperapp from 'hyperapp/dist/hyperapp'
import {userEventAsync, nextTick} from './user-event-async'
import {getQueriesForElement} from '@testing-library/dom'
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 nextTick()
return {
container,
...getQueriesForElement(container),
}
}
// export {render}
// export * from '@testing-library/dom'
test('renders a counter', async () => {
const {getByText} = await render({state, view, actions})
const counter = getByText('0')
await userEventAsync.click(counter)
expect(counter).toHaveTextContent('1')
await userEventAsync.click(counter)
expect(counter).toHaveTextContent('2')
})