-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
61 lines (45 loc) · 1.21 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
import polyfill from './polyfill'
polyfill({
completePolyfill: true,
})
beforeEach(() => {
document.body.innerHTML = ''
global.root = document.createElement('div')
document.body.appendChild(root)
})
it('can be created', () => {
class Foo extends AnonymousElement {}
root.appendChild(new Foo())
expect(root.childNodes[0] instanceof Foo)
})
it('calls createdCallback (like any other custom element)', () => {
let connected = false
class Foo extends AnonymousElement {
connectedCallback() {
connected = true
}
}
root.appendChild(new Foo())
expect(connected).toBe(true)
})
test('.innerHTML === .outerHTML', () => {
class Foo extends AnonymousElement {
connectedCallback() {
this.textContent = 'Hello world'
}
}
root.appendChild(new Foo())
expect(root.childNodes[0].innerHTML).toBe('Hello world')
expect(root.childNodes[0].outerHTML).toBe('Hello world')
})
test('parent.innerHTML', () => {
class Foo extends AnonymousElement {
connectedCallback() {
this.textContent = 'Hello world'
}
}
const parent = document.createElement('h1')
parent.appendChild(new Foo())
root.appendChild(parent)
expect(root.innerHTML).toBe('<h1>Hello world</h1>')
})