From b407469d7fdc4572d23dca646ac2e6717d1ffc19 Mon Sep 17 00:00:00 2001 From: sherwinski Date: Mon, 18 Nov 2024 15:22:39 -0500 Subject: [PATCH] test: update Log mocking in registerForPush tests - Replace manual Log.error spy with Jest mock - Add complete mock implementation for Log methods (error, warn, info, debug) - Add explicit assertions for Log.error calls --- __test__/unit/push/registerForPush.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/__test__/unit/push/registerForPush.test.ts b/__test__/unit/push/registerForPush.test.ts index eac2d4e3e..fda38ce89 100644 --- a/__test__/unit/push/registerForPush.test.ts +++ b/__test__/unit/push/registerForPush.test.ts @@ -7,10 +7,18 @@ import BrowserUserAgent from '../../support/models/BrowserUserAgent'; //stub dismisshelper jest.mock('../../../src/shared/helpers/DismissHelper'); +//stub log +jest.mock('../../../src/shared/libraries/Log', () => ({ + debug: jest.fn(), + trace: jest.fn(), + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), +})); + describe('Register for push', () => { beforeEach(async () => { jest.useFakeTimers(); - jest.spyOn(Log, 'error').mockImplementation(() => {}) await TestEnvironment.initialize({ addPrompts: true, userAgent: BrowserUserAgent.Default, @@ -31,6 +39,7 @@ describe('Register for push', () => { expect(spy).not.toHaveBeenCalled(); OneSignalEvent.trigger(OneSignal.EVENTS.SDK_INITIALIZED); await promise; + expect(Log.error).toHaveBeenCalled(); expect(OneSignal.initialized).toBe(true); expect(spy).toHaveBeenCalledTimes(1); }); @@ -41,6 +50,7 @@ describe('Register for push', () => { const spy = jest.spyOn(InitHelper, 'registerForPushNotifications'); await InitHelper.registerForPushNotifications(); + expect(Log.error).toHaveBeenCalled(); expect(spy).toHaveBeenCalledTimes(1); }); });