Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: explicitly assert for Log.error calls in registerForPush #1206

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __test__/unit/push/registerForPush.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { TestEnvironment } from '../../support/environment/TestEnvironment';
import InitHelper from '../../../src/shared/helpers/InitHelper';
import OneSignalEvent from '../../../src/shared/services/OneSignalEvent';
import Log from '../../../src/shared/libraries/Log';
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();
Expand All @@ -29,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 @@ -39,6 +50,7 @@ describe('Register for push', () => {

const spy = jest.spyOn(InitHelper, 'registerForPushNotifications');
await InitHelper.registerForPushNotifications();
expect(Log.error).toHaveBeenCalled();
expect(spy).toHaveBeenCalledTimes(1);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"build:staging": "ENV=staging yarn transpile:sources && ENV=staging yarn bundle-sw && ENV=staging yarn bundle-sdk && ENV=staging yarn bundle-page-sdk-es6 && ENV=staging build/scripts/publish.sh",
"build:prod": "ENV=production yarn transpile:sources && ENV=production yarn bundle-sw && ENV=production yarn bundle-sdk && ENV=production yarn bundle-page-sdk-es6 && bundlesize && ENV=production build/scripts/publish.sh",
"test": "NODE_OPTIONS=\"--trace-warnings --unhandled-rejections=warn\" yarn run jest --detectOpenHandles --forceExit --runInBand",
"test:watch": "NODE_OPTIONS=\"--trace-warnings --unhandled-rejections=warn\" yarn run jest --detectOpenHandles --forceExit --runInBand --watch",
"publish": "yarn clean && yarn build:prod && yarn",
"build:dev-dev": "./build/scripts/build.sh -f development -t development -a localhost",
"build:dev-prod": "./build/scripts/build.sh -f development -t production",
Expand Down
Loading