forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mithril.test.js
40 lines (36 loc) · 887 Bytes
/
mithril.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
import '@testing-library/jest-dom/extend-expect'
import m from 'mithril'
import {getQueriesForElement, waitFor} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
const Counter = () => {
let count = 0
return {
view: () =>
m(
'button',
{
onclick: () => {
count++
},
},
count,
),
}
}
function render(component) {
const container = document.createElement('div')
m.mount(container, component)
return {
container,
...getQueriesForElement(container),
}
}
// tests:
test('counter increments', async () => {
const {getByText} = render(Counter)
const counter = getByText('0')
userEvent.click(counter)
await waitFor(() => expect(counter).toHaveTextContent('1'))
userEvent.click(counter)
await waitFor(() => expect(counter).toHaveTextContent('2'))
})