diff --git a/src/api/Methods.ts b/src/api/Methods.ts index d405aab3f..631769eac 100644 --- a/src/api/Methods.ts +++ b/src/api/Methods.ts @@ -67,13 +67,15 @@ export function addIntentListener(intent: string, handler: ContextHandler): List return throwIfNoGlobal(() => window.fdc3.addIntentListener(intent, handler)); } -export function addContextListener(contextTypeOrHandler: string | ContextHandler, handler?: ContextHandler): Listener { +export function addContextListener( + contextTypeOrHandler: string | null | ContextHandler, + handler?: ContextHandler +): Listener { + //Handle (deprecated) function signature that allowed contextType argument to be omitted if (typeof contextTypeOrHandler !== 'function') { - return throwIfNoGlobal(() => - window.fdc3.addContextListener(contextTypeOrHandler as string, handler as ContextHandler) - ); + return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler, handler as ContextHandler)); } else { - return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler as ContextHandler)); + return throwIfNoGlobal(() => window.fdc3.addContextListener(null, contextTypeOrHandler as ContextHandler)); } } diff --git a/test/Methods.test.ts b/test/Methods.test.ts index f6d8acdaa..6d525f73d 100644 --- a/test/Methods.test.ts +++ b/test/Methods.test.ts @@ -184,7 +184,7 @@ describe('test ES6 module', () => { expect(window.fdc3.addContextListener).toHaveBeenCalledTimes(2); expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(1, type, handler1); - expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, handler2); + expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, null, handler2); }); test('getSystemChannels should delegate to window.fdc3.getSystemChannels', async () => {