Skip to content

Commit 1803641

Browse files
committed
Update tests and remove console.logs
1 parent d6a3815 commit 1803641

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/analytics/src/helpers.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import { GtagCommand } from './constants';
3030
import { Deferred } from '@firebase/util';
3131
import { ConsentSettings } from './public-types';
32+
import { removeGtagScript } from '../testing/gtag-script-util';
3233

3334
const fakeMeasurementId = 'abcd-efgh-ijkl';
3435
const fakeAppId = 'my-test-app-1234';
@@ -46,6 +47,11 @@ const fakeDynamicConfig: DynamicConfig = {
4647
const fakeDynamicConfigPromises = [Promise.resolve(fakeDynamicConfig)];
4748

4849
describe('Gtag wrapping functions', () => {
50+
afterEach(() => {
51+
delete window['gtag'];
52+
removeGtagScript();
53+
});
54+
4955
it('getOrCreateDataLayer is able to create a new data layer if none exists', () => {
5056
delete window['dataLayer'];
5157
expect(getOrCreateDataLayer('dataLayer')).to.deep.equal([]);
@@ -66,6 +72,15 @@ describe('Gtag wrapping functions', () => {
6672
expect(scriptTag!.src).to.contain(`id=${fakeMeasurementId}`);
6773
});
6874

75+
// The test above essentially already touches this functionality but it is still valuable
76+
it('findGtagScriptOnPage returns gtag instance with matching data layer name', () => {
77+
const defaultDataLayerName = 'dataLayer';
78+
insertScriptTag(defaultDataLayerName, fakeMeasurementId);
79+
const scriptTag = findGtagScriptOnPage(defaultDataLayerName);
80+
expect(scriptTag!.src).to.contain(`l=${defaultDataLayerName}`);
81+
expect(findGtagScriptOnPage('NON_EXISTENT_DATA_LAYER_ID')).to.be.null;
82+
});
83+
6984
describe('wrapOrCreateGtag() when user has not previously inserted a gtag script tag on this page', () => {
7085
afterEach(() => {
7186
delete window['gtag'];

packages/analytics/src/helpers.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,9 @@ export function wrapOrCreateGtag(
320320
/**
321321
* Returns first script tag in DOM matching our gtag url pattern.
322322
*/
323-
// TODO: We'll have this take a datalayer name
324-
// We'll check if a script exists and if it has the same data layer name
325323
export function findGtagScriptOnPage(
326324
dataLayerName: string
327325
): HTMLScriptElement | null {
328-
console.log(findGtagScriptOnPage);
329-
console.log(dataLayerName);
330326
const scriptTags = window.document.getElementsByTagName('script');
331327
for (const tag of Object.values(scriptTags)) {
332328
if (

0 commit comments

Comments
 (0)