11import { SignalsPlugin } from '../signals-plugin'
22
3+ // this test was throwing an error, so I had to mock the sessionStorage --
4+ // no idea why, as sessionStorage is a global object is available in the browser in the test environment
5+ const sessionStorageMock = ( ( ) => {
6+ let store : Record < string , any > = { }
7+ return {
8+ // @ts -ignore
9+ getItem : ( key : string ) => store [ key ] || null ,
10+ setItem : ( key : string , value : unknown ) => {
11+ // @ts -ignore
12+ store [ key ] = value . toString ( )
13+ } ,
14+ removeItem : ( key : string ) => {
15+ // @ts -ignore
16+ delete store [ key ]
17+ } ,
18+ clear : ( ) => {
19+ store = { }
20+ } ,
21+ }
22+ } ) ( )
23+
24+ Object . defineProperty ( window , 'sessionStorage' , {
25+ value : sessionStorageMock ,
26+ } )
327/**
428 * This should be tested at the integration level
529 * A few tests, just for example purposes.
630 */
731describe ( SignalsPlugin , ( ) => {
8- let plugin : SignalsPlugin
9- beforeEach ( ( ) => {
10- plugin = new SignalsPlugin ( )
11- } )
12-
1332 test ( 'onSignal method registers callback' , ( ) => {
33+ const plugin = new SignalsPlugin ( )
1434 const callback = jest . fn ( )
1535 const emitterSpy = jest . spyOn ( plugin . signals . signalEmitter , 'subscribe' )
1636 plugin . onSignal ( callback )
@@ -19,6 +39,7 @@ describe(SignalsPlugin, () => {
1939 } )
2040
2141 test ( 'addSignal method emits signal' , ( ) => {
42+ const plugin = new SignalsPlugin ( )
2243 const signal = { data : 'test' } as any
2344 const emitterSpy = jest . spyOn ( plugin . signals . signalEmitter , 'emit' )
2445 plugin . addSignal ( signal )
0 commit comments