Skip to content

Commit 80ae05e

Browse files
committed
Stub logger instead of console.log
1 parent dc7b7f1 commit 80ae05e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/analytics/src/helpers.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import { GtagCommand, GTAG_URL } from './constants';
3232
import { Deferred } from '@firebase/util';
3333
import { ConsentSettings } from './public-types';
3434
import { removeGtagScripts } from '../testing/gtag-script-util';
35+
import { logger } from './logger';
36+
import { AnalyticsError, ERROR_FACTORY } from './errors';
3537

3638
const fakeMeasurementId = 'abcd-efgh-ijkl';
3739
const fakeAppId = 'my-test-app-1234';
@@ -84,13 +86,16 @@ describe('Trusted Types policies and functions', () => {
8486

8587
it('createGtagTrustedTypesScriptURL rejects URLs with non-gtag base', () => {
8688
const NON_GTAG_URL = 'http://iamnotgtag.com';
87-
const consoleErrorStub = stub(console, 'error');
89+
const loggerWarnStub = stub(logger, 'warn');
90+
const errorMessage = ERROR_FACTORY.create(
91+
AnalyticsError.INVALID_GTAG_RESOURCE,
92+
{
93+
gtagURL: NON_GTAG_URL
94+
}
95+
).message;
8896

8997
expect(createGtagTrustedTypesScriptURL(NON_GTAG_URL)).to.equal('');
90-
expect(consoleErrorStub).to.be.calledWith(
91-
'Unknown gtag resource!',
92-
NON_GTAG_URL
93-
);
98+
expect(loggerWarnStub).to.be.calledWith(errorMessage);
9499
});
95100
});
96101

packages/analytics/src/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type GtagConfigOrEventParams = ControlParams & EventParams & CustomParams;
3434
*/
3535
export function createGtagTrustedTypesScriptURL(url: string): string {
3636
if (!url.startsWith(GTAG_URL)) {
37-
console.error('Unknown gtag resource!', url);
3837
const err = ERROR_FACTORY.create(AnalyticsError.INVALID_GTAG_RESOURCE, {
3938
gtagURL: url
4039
});

0 commit comments

Comments
 (0)