forked from alpinejs/alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.spec.js
50 lines (37 loc) · 1.2 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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').textContent).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').textContent).toEqual('') })
document.querySelector('button').click()
await wait(() => { expect(document.querySelector('span').textContent).toEqual('bar') })
})
test('x-text on SVG elements', async () => {
document.body.innerHTML = `
<div x-data="{ foo: 'bar' }">
<svg>
<text x-text="foo"></text>
</svg>
</div>
`
Alpine.start()
await wait(() => { expect(document.querySelector('text').textContent).toEqual('bar') })
})