forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte.test.js
34 lines (30 loc) · 802 Bytes
/
svelte.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
import 'jest-dom/extend-expect'
import {getQueriesForElement, fireEvent} from 'dom-testing-library'
import * as svelte from 'svelte'
const counterTemplate = `
<div>
<button on:click='set({ count: count + 1 })'>
{count}
</button>
</div>
`
function render(template, options) {
const container = document.createElement('div')
const Constructor = svelte.create(template)
new Constructor({
target: container,
...options,
})
return {
container,
...getQueriesForElement(container),
}
}
test('counter increments', () => {
const {getByText} = render(counterTemplate, {data: {count: 0}})
const counter = getByText('0')
fireEvent.click(counter)
expect(counter).toHaveTextContent('1')
fireEvent.click(counter)
expect(counter).toHaveTextContent('2')
})