forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dojo.test.ts
39 lines (36 loc) · 1.14 KB
/
dojo.test.ts
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
import ProjectorMixin from '@dojo/framework/widget-core/mixins/Projector'
import WidgetBase from '@dojo/framework/widget-core/WidgetBase'
import {v} from '@dojo/framework/widget-core/d'
import {Constructor} from '@dojo/framework/widget-core/interfaces'
import {getQueriesForElement} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
import '@testing-library/jest-dom/extend-expect'
class Counter extends WidgetBase {
count = 0
increment() {
this.count++
this.invalidate()
}
render() {
return v('div', [v('button', {onclick: this.increment}, [`${this.count}`])])
}
}
function render(ui: Constructor<WidgetBase>) {
const container = document.createElement('div')
const Projector = ProjectorMixin(ui)
const projector = new Projector()
projector.async = false
projector.append(container)
return {
container,
...getQueriesForElement(container),
}
}
test('renders counter', () => {
const {getByText} = render(Counter)
const counter = getByText('0')
userEvent.click(counter)
expect(counter).toHaveTextContent('1')
userEvent.click(counter)
expect(counter).toHaveTextContent('2')
})