Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 14, 2024
1 parent 7d9bd0e commit f517f67
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import { SignalsPlugin } from '../signals-plugin'

// this test was throwing an error, so I had to mock the sessionStorage --
// no idea why, as sessionStorage is a global object is available in the browser in the test environment
const sessionStorageMock = (() => {
let store: Record<string, any> = {}
return {
// @ts-ignore
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: unknown) => {
// @ts-ignore
store[key] = value.toString()
},
removeItem: (key: string) => {
// @ts-ignore
delete store[key]
},
clear: () => {
store = {}
},
}
})()

Object.defineProperty(window, 'sessionStorage', {
value: sessionStorageMock,
})
/**
* This should be tested at the integration level
* A few tests, just for example purposes.
*/
describe(SignalsPlugin, () => {
let plugin: SignalsPlugin
beforeEach(() => {
plugin = new SignalsPlugin()
})

test('onSignal method registers callback', () => {
const plugin = new SignalsPlugin()
const callback = jest.fn()
const emitterSpy = jest.spyOn(plugin.signals.signalEmitter, 'subscribe')
plugin.onSignal(callback)
Expand All @@ -19,6 +39,7 @@ describe(SignalsPlugin, () => {
})

test('addSignal method emits signal', () => {
const plugin = new SignalsPlugin()
const signal = { data: 'test' } as any
const emitterSpy = jest.spyOn(plugin.signals.signalEmitter, 'emit')
plugin.addSignal(signal)
Expand Down

0 comments on commit f517f67

Please sign in to comment.