File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,13 +55,6 @@ const strategies: Record<string, Strategy> = {
5555 visible
5656}
5757
58- export function addStrategy ( name : string , strategy : Strategy ) {
59- if ( name in strategies ) {
60- throw new Error ( `Strategy ${ name } already exists!` )
61- }
62- strategies [ name ] = strategy
63- }
64-
6558const timers = new WeakMap < Element , number > ( )
6659function scan ( node : Element = document . body ) {
6760 cancelAnimationFrame ( timers . get ( node ) || 0 )
Original file line number Diff line number Diff line change 11import { expect , fixture , html } from '@open-wc/testing'
22import { 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 ( / a l r e a d y e x i s t s / )
29- } )
30- } )
3+ import { lazyDefine } from '../src/lazy-define.js'
314
325describe ( 'lazyDefine' , ( ) => {
336 describe ( 'ready strategy' , ( ) => {
You can’t perform that action at this time.
0 commit comments