Skip to content

Commit daeb4b8

Browse files
committed
Add unit tests
1 parent 0f56a1d commit daeb4b8

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

packages-exp/messaging-compat/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const karmaBase = require('../../config/karma.base');
1919

20-
const files = [`src/**/*.test.ts`];
20+
const files = ['test/**/*'];
2121

2222
module.exports = function (config) {
2323
const karmaConfig = {

packages-exp/messaging-compat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build:deps": "lerna run --scope @firebase/'messaging-compat' --include-dependencies build",
2121
"build:release": "rollup -c rollup.config.release.js",
2222
"dev": "rollup -c -w",
23-
"test": "run-p test:karma type-check lint ",
23+
"test": "run-p test:karma",
2424
"test:ci": "node ../../scripts/run_tests_in_ci.js",
2525
"test:karma": "karma start --single-run",
2626
"test:debug": "karma start --browsers=Chrome --auto-watch",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { FirebaseApp } from '@firebase/app-compat';
19+
import { FirebaseMessaging } from '@firebase/messaging-exp';
20+
21+
export function getFakeApp(): FirebaseApp {
22+
return {
23+
name: 'appName',
24+
options: {
25+
apiKey: 'apiKey',
26+
projectId: 'projectId',
27+
authDomain: 'authDomain',
28+
messagingSenderId: 'messagingSenderId',
29+
databaseURL: 'databaseUrl',
30+
storageBucket: 'storageBucket',
31+
appId: '1:777777777777:web:d93b5ca1475efe57'
32+
},
33+
automaticDataCollectionEnabled: true,
34+
delete: async () => {}
35+
};
36+
}
37+
38+
export function getFakeModularMessaging(): FirebaseMessaging {
39+
return {};
40+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as messagingModule from '@firebase/messaging-exp';
19+
import * as messagingModuleSwComponent from '@firebase/messaging-exp/sw';
20+
21+
import { getFakeApp, getFakeModularMessaging } from './fakes';
22+
23+
import { MessagingCompat } from '../src/messaging-compat';
24+
import { expect } from 'chai';
25+
import { stub } from 'sinon';
26+
27+
describe('messagingCompat', () => {
28+
const messagingCompat = new MessagingCompat(
29+
getFakeApp(),
30+
getFakeModularMessaging()
31+
);
32+
33+
//Stubs
34+
const getTokenStub = stub(messagingModule, 'getToken');
35+
const deleteTokenStub = stub(messagingModule, 'deleteToken');
36+
const onMessageStub = stub(messagingModule, 'onMessage');
37+
const onBackgroundMessageStub = stub(
38+
messagingModuleSwComponent,
39+
'onBackgroundMessage'
40+
);
41+
42+
it('routes messagingCompat.getToken to modular SDK', () => {
43+
void messagingCompat.getToken();
44+
expect(getTokenStub.called).to.be.true;
45+
});
46+
47+
it('routes messagingCompat.deleteToken to modular SDK', () => {
48+
void messagingCompat.deleteToken();
49+
expect(deleteTokenStub.called).to.be.true;
50+
});
51+
52+
it('routes messagingCompat.onMessage to modular SDK', () => {
53+
messagingCompat.onMessage(_ => {});
54+
expect(onMessageStub.called).to.be.true;
55+
});
56+
57+
it('routes messagingCompat.onBackgroundMessage to modular SDK', () => {
58+
messagingCompat.onBackgroundMessage(_ => {});
59+
expect(onBackgroundMessageStub.called).to.be.true;
60+
});
61+
});

0 commit comments

Comments
 (0)