Skip to content

Commit 4c93e53

Browse files
committed
Add API test for getGoogleAnalyticsClientId
1 parent 3e401cb commit 4c93e53

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/analytics/src/api.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import '../testing/setup';
2121
import { getFullApp } from '../testing/get-fake-firebase-services';
2222
import {
2323
getAnalytics,
24+
getGoogleAnalyticsClientId,
2425
initializeAnalytics,
2526
setConsent,
2627
setDefaultEventParameters
@@ -35,6 +36,8 @@ import {
3536
defaultEventParametersForInit
3637
} from './functions';
3738
import { ConsentSettings } from './public-types';
39+
import { GtagCommand } from './constants';
40+
import * as util from '@firebase/util';
3841

3942
describe('FirebaseAnalytics API tests', () => {
4043
let initStub: SinonStub = stub();
@@ -154,4 +157,19 @@ describe('FirebaseAnalytics API tests', () => {
154157
consentParametersForInit
155158
);
156159
});
160+
it('getGoogleAnalyticsClientId() calls gtag "get" through wrappedGtagFunction', () => {
161+
stub(factory, 'wrappedGtagFunction').get(() => wrappedGtag);
162+
stub(util, 'getModularInstance').returns({
163+
app: { options: { measurementId: 'measurement-id-1' } }
164+
});
165+
app = getFullApp({ ...fakeAppParams, measurementId: 'measurement-id-1' });
166+
const analyticsInstance = initializeAnalytics(app);
167+
const id = getGoogleAnalyticsClientId(analyticsInstance);
168+
console.log({ didWeGetTheId: id });
169+
expect(wrappedGtag).to.have.been.calledWith(
170+
GtagCommand.GET,
171+
'measurement-id-1',
172+
'client_id'
173+
);
174+
});
157175
});

0 commit comments

Comments
 (0)