Skip to content

Commit d7846c1

Browse files
committed
Add a test
1 parent 0e26c15 commit d7846c1

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

packages-exp/analytics-exp/src/initialize-analytics.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function stubFetch(): void {
4848
fetchStub.returns(Promise.resolve(mockResponse));
4949
}
5050

51-
describe('initializeIds()', () => {
51+
describe('initializeAnalytics()', () => {
5252
const gtagStub: SinonStub = stub();
5353
const dynamicPromisesList: Array<Promise<DynamicConfig>> = [];
5454
const measurementIdToAppId: { [key: string]: string } = {};
@@ -79,6 +79,24 @@ describe('initializeIds()', () => {
7979
update: true
8080
});
8181
});
82+
it('calls gtag config with options if provided', async () => {
83+
stubFetch();
84+
await initializeAnalytics(
85+
app,
86+
dynamicPromisesList,
87+
measurementIdToAppId,
88+
fakeInstallations,
89+
gtagStub,
90+
'dataLayer',
91+
{ config: { 'send_page_view': false } }
92+
);
93+
expect(gtagStub).to.be.calledWith(GtagCommand.CONFIG, fakeMeasurementId, {
94+
'firebase_id': fakeFid,
95+
'origin': 'firebase',
96+
update: true,
97+
'send_page_view': false
98+
});
99+
});
82100
it('puts dynamic fetch promise into dynamic promises list', async () => {
83101
stubFetch();
84102
await initializeAnalytics(

packages-exp/analytics-exp/testing/integration-tests/integration.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('FirebaseAnalytics Integration Smoke Tests', () => {
7575
it('logEvent() sends correct network request.', async () => {
7676
app = initializeApp(config);
7777
logEvent(initializeAnalytics(app), 'login', { method: 'email' });
78-
async function checkForEventCalls(): Promise<number> {
78+
async function checkForEventCalls(): Promise<PerformanceEntry[]> {
7979
await new Promise(resolve => setTimeout(resolve, RETRY_INTERVAL));
8080
const resources = performance.getEntriesByType('resource');
8181
const callsWithEvent = resources.filter(
@@ -86,11 +86,12 @@ describe('FirebaseAnalytics Integration Smoke Tests', () => {
8686
if (callsWithEvent.length === 0) {
8787
return checkForEventCalls();
8888
} else {
89-
return callsWithEvent.length;
89+
return callsWithEvent;
9090
}
9191
}
92-
const eventCallCount = await checkForEventCalls();
93-
expect(eventCallCount).to.equal(1);
92+
const eventCalls = await checkForEventCalls();
93+
expect(eventCalls.length).to.equal(1);
94+
expect(eventCalls[0].name).to.include('method=email');
9495
});
9596
it('getAnalytics() does not throw if called after initializeAnalytics().', async () => {
9697
const analyticsInstance = getAnalytics(app);

0 commit comments

Comments
 (0)