Skip to content

Commit f517f67

Browse files
committed
wip
1 parent 7d9bd0e commit f517f67

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

packages/signals/signals/src/plugin/__tests__/signals-plugin.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
import { 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
*/
731
describe(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

Comments
 (0)