Skip to content

Commit

Permalink
Merge pull request #1206 from OneSignal/silence-push-error
Browse files Browse the repository at this point in the history
test: explicitly assert for Log.error calls in `registerForPush`
  • Loading branch information
sherwinski authored Nov 18, 2024
2 parents aa3c45b + b407469 commit 41a141b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 41a141b

Please sign in to comment.