|
| 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 | +}); |
0 commit comments