forked from alpinejs/alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnesting.spec.js
45 lines (33 loc) · 1.16 KB
/
nesting.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
import Alpine from 'alpinejs'
import { wait } from '@testing-library/dom'
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms))
global.MutationObserver = class {
observe() {}
}
test('can nest components', async () => {
document.body.innerHTML = `
<div x-data="{ foo: 'bar' }">
<span x-text="foo"></span>
<div x-data="{ foo: 'bob' }">
<button x-on:click="foo = 'baz'">Something</button>
</div>
</div>
`
Alpine.start()
expect(document.querySelector('span').textContent).toEqual('bar')
document.querySelector('button').click()
await timeout(20)
await wait(() => { expect(document.querySelector('span').textContent).toEqual('bar') })
})
test('can access parent properties after nested components', async () => {
document.body.innerHTML = `
<div x-data="{ foo: 'bar' }">
<div x-data="{ foo: 'bob' }">
<button x-on:click="foo = 'baz'">Something</button>
</div>
<span x-text="foo"></span>
</div>
`
Alpine.start()
expect(document.querySelector('span').textContent).toEqual('bar')
})