Skip to content

Commit ec912f2

Browse files
koddssonkeithamus
andcommitted
Add tests for addStrategy
Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
1 parent 943c929 commit ec912f2

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/lazy-define.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {expect, fixture, html} from '@open-wc/testing'
2+
import {spy} from 'sinon'
3+
import {addStrategy, lazyDefine} from '../src/lazy-define.js'
4+
5+
describe('addStrategy', () => {
6+
let strategy: ReturnType<typeof spy>
7+
let promise: Promise<void>
8+
let resolve: () => void
9+
10+
beforeEach(() => {
11+
strategy = spy(() => promise = new Promise((res) => resolve = res))
12+
})
13+
14+
it('adds a new strategy', async () => {
15+
const onDefine = spy()
16+
lazyDefine('foo-bar', onDefine)
17+
addStrategy('test', strategy)
18+
await fixture(html`<foo-bar data-load-on="test"></foo-bar>`)
19+
20+
expect(strategy).to.be.calledOnceWith('foo-bar')
21+
expect(onDefine).to.have.callCount(0)
22+
resolve()
23+
await promise
24+
expect(onDefine).to.be.callCount(1)
25+
})
26+
27+
it("doesn't overwrite a existing strategy", () => {
28+
expect(() => addStrategy('ready', spy())).to.throw(/already exists/)
29+
})
30+
})
31+
32+
describe('lazyDefine', () => {
33+
it('', () => {})
34+
})

0 commit comments

Comments
 (0)