Skip to content

Commit

Permalink
test: update Log mocking in registerForPush tests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
sherwinski committed Nov 18, 2024
1 parent ffad6d6 commit b407469
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion __test__/unit/push/registerForPush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});
Expand All @@ -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);
});
});

0 comments on commit b407469

Please sign in to comment.