forked from alpinejs/alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.spec.js
36 lines (26 loc) · 891 Bytes
/
text.spec.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
import Alpine from 'alpinejs'
import { wait } from '@testing-library/dom'
global.MutationObserver = class {
observe() {}
}
test('x-text on init', async () => {
document.body.innerHTML = `
<div x-data="{ foo: 'bar' }">
<span x-text="foo"></span>
</div>
`
Alpine.start()
await wait(() => { expect(document.querySelector('span').innerText).toEqual('bar') })
})
test('x-text on triggered update', async () => {
document.body.innerHTML = `
<div x-data="{ foo: '' }">
<button x-on:click="foo = 'bar'"></button>
<span x-text="foo"></span>
</div>
`
Alpine.start()
await wait(() => { expect(document.querySelector('span').innerText).toEqual('') })
document.querySelector('button').click()
await wait(() => { expect(document.querySelector('span').innerText).toEqual('bar') })
})