forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preact.test.js
35 lines (32 loc) · 916 Bytes
/
preact.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
/** @jsx Preact.h */
import 'jest-dom/extend-expect'
import * as Preact from 'preact'
import {fireEventAsync} from './fire-event-async'
import {getQueriesForElement, wait} from 'dom-testing-library'
class Counter extends Preact.Component {
state = {count: 0}
increment = () => this.setState(({count}) => ({count: count + 1}))
render() {
return (
<div>
<button onClick={this.increment}>{this.state.count}</button>
</div>
)
}
}
function render(ui) {
const container = document.createElement('div')
Preact.render(ui, container)
return {
container,
...getQueriesForElement(container),
}
}
test('renders a counter', async () => {
const {getByText} = render(<Counter />)
const counter = getByText('0')
await fireEventAsync.click(counter)
expect(counter).toHaveTextContent('1')
await fireEventAsync.click(counter)
expect(counter).toHaveTextContent('2')
})