forked from alpinejs/alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow.spec.js
42 lines (29 loc) · 1.21 KB
/
show.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
import Alpine from 'alpinejs'
import { wait } from '@testing-library/dom'
global.MutationObserver = class {
observe() {}
}
test('x-show toggles display: none; with no other style attributes', async () => {
document.body.innerHTML = `
<div x-data="{ show: true }">
<span x-show="show"></span>
<button x-on:click="show = false"></button>
</div>
`
Alpine.start()
expect(document.querySelector('span').getAttribute('style')).toEqual(null)
document.querySelector('button').click()
await wait(() => { expect(document.querySelector('span').getAttribute('style')).toEqual('display: none;') })
})
test('x-show toggles display: none; with no other style attributes', async () => {
document.body.innerHTML = `
<div x-data="{ show: true }">
<span x-show="show" style="color: blue;"></span>
<button x-on:click="show = false"></button>
</div>
`
Alpine.start()
expect(document.querySelector('span').getAttribute('style')).toEqual('color: blue;')
document.querySelector('button').click()
await wait(() => { expect(document.querySelector('span').getAttribute('style')).toEqual('color: blue; display: none;') })
})