@@ -19,15 +19,21 @@ import { expect } from 'chai';
19
19
import { SinonStub , stub } from 'sinon' ;
20
20
import '../testing/setup' ;
21
21
import { getFullApp } from '../testing/get-fake-firebase-services' ;
22
- import { getAnalytics , initializeAnalytics } from './api' ;
22
+ import {
23
+ getAnalytics ,
24
+ initializeAnalytics ,
25
+ setDefaultEventParameters
26
+ } from './api' ;
23
27
import { FirebaseApp , deleteApp } from '@firebase/app' ;
24
28
import { AnalyticsError } from './errors' ;
25
29
import * as init from './initialize-analytics' ;
26
30
const fakeAppParams = { appId : 'abcdefgh12345:23405' , apiKey : 'AAbbCCdd12345' } ;
31
+ import * as factory from './factory' ;
27
32
28
33
describe ( 'FirebaseAnalytics API tests' , ( ) => {
29
34
let initStub : SinonStub = stub ( ) ;
30
35
let app : FirebaseApp ;
36
+ const wrappedGtag : SinonStub = stub ( ) ;
31
37
32
38
beforeEach ( ( ) => {
33
39
initStub = stub ( init , '_initializeAnalytics' ) . resolves (
@@ -94,4 +100,29 @@ describe('FirebaseAnalytics API tests', () => {
94
100
const analyticsInstance = initializeAnalytics ( app ) ;
95
101
expect ( getAnalytics ( app ) ) . to . equal ( analyticsInstance ) ;
96
102
} ) ;
103
+ it ( 'setDefaultEventParameters() updates defaultEventParametersForInit if gtag does not exist ' , ( ) => {
104
+ const eventParametersForInit = {
105
+ 'github_user' : 'dwyfrequency' ,
106
+ 'company' : 'google'
107
+ } ;
108
+ app = getFullApp ( fakeAppParams ) ;
109
+ setDefaultEventParameters ( eventParametersForInit ) ;
110
+ expect ( factory . defaultEventParametersForInit ) . to . deep . equal (
111
+ eventParametersForInit
112
+ ) ;
113
+ } ) ;
114
+
115
+ it ( 'setDefaultEventParameters() calls gtag set if wrappedGtagFunction exists' , ( ) => {
116
+ const eventParametersForInit = {
117
+ 'github_user' : 'dwyfrequency' ,
118
+ 'company' : 'google'
119
+ } ;
120
+ stub ( factory , 'wrappedGtagFunction' ) . get ( ( ) => wrappedGtag ) ;
121
+ app = getFullApp ( fakeAppParams ) ;
122
+ setDefaultEventParameters ( eventParametersForInit ) ;
123
+ expect ( wrappedGtag ) . to . have . been . calledWithExactly (
124
+ 'set' ,
125
+ eventParametersForInit
126
+ ) ;
127
+ } ) ;
97
128
} ) ;
0 commit comments