-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathexternal.spec.js
41 lines (33 loc) · 924 Bytes
/
external.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
let { morph } = require('@alpinejs/morph')
let createElement = require('./createElement.js')
test('text content', () => assertPatch(
`<div>foo</div>`,
`<div>bar</div>`
))
test('change tag', () => assertPatch(
`<div><div>foo</div></div>`,
`<div><span>foo</span></div>`
))
test('add child', () => assertPatch(
`<div>foo</div>`,
`<div>foo <h1>baz</h1></div>`
))
test('remove child', () => assertPatch(
`<div>foo <h1>baz</h1></div>`,
`<div>foo</div>`
))
test('add attribute', () => assertPatch(
`<div>foo</div>`,
`<div foo="bar">foo</div>`
))
test('remove attribute', () => assertPatch(
`<div foo="bar">foo</div>`,
`<div>foo</div>`
))
test('change attribute', () => assertPatch(
`<div foo="bar">foo</div>`,
`<div foo="baz">foo</div>`
))
async function assertPatch(before, after) {
expect((await morph(createElement(before), after)).outerHTML).toEqual(after)
}