Skip to content

Commit d4e1bbb

Browse files
committed
add test for initializePerforamnce
1 parent d148196 commit d4e1bbb

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 { expect } from 'chai';
19+
import { stub } from 'sinon';
20+
import { initializePerformance } from './index';
21+
import { ERROR_FACTORY, ErrorCode } from './utils/errors';
22+
import * as firebase from '@firebase/app-exp';
23+
import { Provider } from '@firebase/component';
24+
import '../test/setup';
25+
26+
const fakeFirebaseConfig = {
27+
apiKey: 'api-key',
28+
authDomain: 'project-id.firebaseapp.com',
29+
databaseURL: 'https://project-id.firebaseio.com',
30+
projectId: 'project-id',
31+
storageBucket: 'project-id.appspot.com',
32+
messagingSenderId: 'sender-id',
33+
appId: '1:111:web:a1234'
34+
};
35+
36+
const fakeFirebaseApp = ({
37+
options: fakeFirebaseConfig
38+
} as unknown) as firebase.FirebaseApp;
39+
40+
describe('Firebase Performance > initializePerformance()', () => {
41+
it('throws if a perf instance has already been created', () => {
42+
stub(firebase, '_getProvider').returns(({
43+
isInitialized: () => true
44+
} as unknown) as Provider<'performance-exp'>);
45+
const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_INITIALIZED);
46+
expect(() => initializePerformance(fakeFirebaseApp)).to.throw(
47+
expectedError.message
48+
);
49+
});
50+
});

packages-exp/performance-exp/src/utils/string_merger.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import { expect } from 'chai';
1919

2020
import { mergeStrings } from './string_merger';
2121
import { FirebaseError } from '@firebase/util';
22-
// import { ERROR_FACTORY, ErrorCode } from './errors';
2322
import '../../test/setup';
2423

2524
describe('Firebase Performance > string_merger', () => {
2625
describe('#mergeStrings', () => {
2726
it('Throws exception when string length has | diff | > 1', () => {
28-
// const expectedError = ERROR_FACTORY.create(ErrorCode.INVALID_STRING_MERGER_PARAMETER);
2927
expect(() => mergeStrings('', '123')).to.throw(
3028
FirebaseError,
3129
'performance/invalid String merger input'

0 commit comments

Comments
 (0)