16
16
*/
17
17
18
18
import { expect } from 'chai' ;
19
- import { stub } from 'sinon' ;
20
19
import { initializePerformance } from './index' ;
21
20
import { ERROR_FACTORY , ErrorCode } from './utils/errors' ;
22
- import * as firebase from '@firebase/app-exp' ;
23
- import { Provider } from '@firebase/component' ;
24
21
import '../test/setup' ;
22
+ import { deleteApp , FirebaseApp , initializeApp } from '@firebase/app-exp' ;
25
23
26
24
const fakeFirebaseConfig = {
27
25
apiKey : 'api-key' ,
@@ -33,17 +31,44 @@ const fakeFirebaseConfig = {
33
31
appId : '1:111:web:a1234'
34
32
} ;
35
33
36
- const fakeFirebaseApp = ( {
37
- options : fakeFirebaseConfig
38
- } as unknown ) as firebase . FirebaseApp ;
34
+ // const fakeFirebaseApp = ({
35
+ // options: fakeFirebaseConfig
36
+ // } as unknown) as firebase.FirebaseApp;
39
37
40
38
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' > ) ;
39
+ let app : FirebaseApp ;
40
+ beforeEach ( ( ) => {
41
+ app = initializeApp ( fakeFirebaseConfig ) ;
42
+ } ) ;
43
+ afterEach ( ( ) => {
44
+ return deleteApp ( app ) ;
45
+ } ) ;
46
+ it ( 'returns same instance if given same (no) params a second time' , ( ) => {
47
+ const performanceInstance = initializePerformance ( app ) ;
48
+ expect ( initializePerformance ( app ) ) . to . equal ( performanceInstance ) ;
49
+ } ) ;
50
+ it ( 'returns same instance if given same params a second time' , ( ) => {
51
+ const performanceInstance = initializePerformance ( app , { dataCollectionEnabled : false } ) ;
52
+ expect ( initializePerformance ( app , { dataCollectionEnabled : false } ) ) . to . equal ( performanceInstance ) ;
53
+ } ) ;
54
+ it ( 'throws if called with params after being called with no params' , ( ) => {
55
+ initializePerformance ( app ) ;
56
+ const expectedError = ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
57
+ expect ( ( ) => initializePerformance ( app , { dataCollectionEnabled : false } ) ) . to . throw (
58
+ expectedError . message
59
+ ) ;
60
+ } ) ;
61
+ it ( 'throws if called with no params after being called with params' , ( ) => {
62
+ initializePerformance ( app , { instrumentationEnabled : false } ) ;
63
+ const expectedError = ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
64
+ expect ( ( ) => initializePerformance ( app ) ) . to . throw (
65
+ expectedError . message
66
+ ) ;
67
+ } ) ;
68
+ it ( 'throws if called a second time with different params' , ( ) => {
69
+ initializePerformance ( app , { instrumentationEnabled : true } ) ;
45
70
const expectedError = ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
46
- expect ( ( ) => initializePerformance ( fakeFirebaseApp ) ) . to . throw (
71
+ expect ( ( ) => initializePerformance ( app , { instrumentationEnabled : false } ) ) . to . throw (
47
72
expectedError . message
48
73
) ;
49
74
} ) ;
0 commit comments