From bf46430205da8e0100550f74461cf196a9628667 Mon Sep 17 00:00:00 2001 From: Dan Tam Date: Thu, 18 Jun 2020 18:05:21 -0700 Subject: [PATCH] fix(timing): skip warning for falsy value --- src/core.js | 2 +- test/functionality/timing.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 75221a4..c297502 100644 --- a/src/core.js +++ b/src/core.js @@ -272,7 +272,7 @@ export function timing( trackerNames ) { if (typeof ga === 'function') { - if (!category || !variable || !value || typeof value !== 'number') { + if (!category || !variable || typeof value !== 'number') { warn( 'args.category, args.variable ' + 'AND args.value are required in timing() ' + diff --git a/test/functionality/timing.test.js b/test/functionality/timing.test.js index af4f573..7be6e15 100644 --- a/test/functionality/timing.test.js +++ b/test/functionality/timing.test.js @@ -79,6 +79,20 @@ describe('timing()', () => { ); }); + it('should not warn if value arg is 0, a falsy number', () => { + ReactGA.initialize('foo'); + ReactGA.timing({ + category: 'Test', + variable: 'Timing test', + value: 0 + }); + expect(spies.warn).not.toHaveBeenCalledWith( + '[react-ga]', + 'args.category, args.variable AND args.value are required in timing() ' + + 'AND args.value has to be a number' + ); + }); + it('should warn if value arg is not a number', () => { ReactGA.initialize('foo'); ReactGA.timing({