diff options
author | Idan Amit <ia096e@intl.att.com> | 2018-08-13 17:58:53 +0300 |
---|---|---|
committer | Idan Amit <ia096e@intl.att.com> | 2018-08-13 18:55:16 +0300 |
commit | e7154335e26e3e68bedd7ef09831982a33ab3aeb (patch) | |
tree | b71ff637504073ff884aa28a4955d573ddcab8c6 /lib/plugin-pubusb.spec.ts | |
parent | de26cd4b417cac55e38b8830b729d6443564f2fc (diff) |
Added tests to sdc-pubsub
Added tests files and coverage to sdc-pubsub
Change-Id: I45146ae8d18f229d92afb60208532a1a0ca4192a
Issue-ID: SDC-1542
Signed-off-by: Idan Amit <ia096e@intl.att.com>
Diffstat (limited to 'lib/plugin-pubusb.spec.ts')
-rw-r--r-- | lib/plugin-pubusb.spec.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/plugin-pubusb.spec.ts b/lib/plugin-pubusb.spec.ts new file mode 100644 index 0000000..1eb6eda --- /dev/null +++ b/lib/plugin-pubusb.spec.ts @@ -0,0 +1,53 @@ +import {PluginPubSub} from './plugin-pubsub'; + +declare const window: Window; + +describe('BasePubSub Tests', () => { + let pluginPubSub: PluginPubSub; + + let testSub: string = 'testSub'; + let testParentUrl: string = 'http://127.0.0.1'; + let testEventsToWait: Array<string> = ['CHECK_IN', 'WINDOW_OUT']; + + beforeEach(() => { + pluginPubSub = new PluginPubSub(testSub, testParentUrl, testEventsToWait); + }); + + describe('constructor tests', () => { + it('should init class property', () => { + expect(pluginPubSub.subscribers.size).toBe(1); + expect(pluginPubSub.eventsCallbacks.length).toBe(0); + expect(pluginPubSub.eventsToWait.size).toBe(0); + expect(pluginPubSub.clientId).toBe('testSub'); + }); + }); + + describe('subscribe function tests', () => { + it('should call notify function with the PLUGIN_REGISTER event and the register data', () => { + pluginPubSub.notify = jest.fn(); + + let wantedRegisterData = { + pluginId: testSub, + eventsToWait: [] + }; + + pluginPubSub.subscribe(); + + expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_REGISTER', wantedRegisterData); + }) + }); + + describe('unsubscribe function tests', () => { + it('should call notify function with the PLUGIN_UNREGISTER event and the unregister data', () => { + pluginPubSub.notify = jest.fn(); + + let wantedUnregisterData = { + pluginId: testSub, + }; + + pluginPubSub.unsubscribe(); + + expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_UNREGISTER', wantedUnregisterData); + }) + }); +});
\ No newline at end of file |