Skip to content

Commit a0c45c4

Browse files
koddssonkeithamus
andcommitted
Add some basic tests for lazyDefine
Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
1 parent ec912f2 commit a0c45c4

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

test/lazy-define.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,23 @@ describe('addStrategy', () => {
3030
})
3131

3232
describe('lazyDefine', () => {
33-
it('', () => {})
33+
it('scans the whole document on first call', async () => {
34+
const onDefine = spy()
35+
lazyDefine('scan-document-test', onDefine)
36+
await fixture(html`<scan-document-test></scan-document-test>`)
37+
38+
await new Promise<unknown>(resolve => requestAnimationFrame(resolve))
39+
40+
expect(onDefine).to.be.callCount(1)
41+
})
42+
it('initializes dynamic elements that are defined after the document is ready', async () => {
43+
const onDefine = spy()
44+
await fixture(html`<later-defined-element-test></later-defined-element-test>`)
45+
lazyDefine('later-defined-element-test', onDefine)
46+
47+
await new Promise<unknown>(resolve => requestAnimationFrame(resolve))
48+
49+
expect(onDefine).to.be.callCount(1)
50+
})
51+
it("doesn't call the same callback twice", () => {})
3452
})

0 commit comments

Comments
 (0)