From 5871f667b90a3d9ed80438462949c7f65c68be69 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 6 Apr 2020 10:55:51 +0200 Subject: [PATCH] onRouteUpdate test tweaks --- src/__tests__/gatsby-browser.js | 10 +++++----- src/gatsby-browser.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/__tests__/gatsby-browser.js b/src/__tests__/gatsby-browser.js index c1236e3..3c81acf 100644 --- a/src/__tests__/gatsby-browser.js +++ b/src/__tests__/gatsby-browser.js @@ -18,13 +18,13 @@ describe('gatsby-plugin-matomo', () => { }) it('does not send page view', () => { - onRouteUpdate({}) + onRouteUpdate({}, {}) expect(window._paq.push).not.toHaveBeenCalled() }) it('sends page view in dev mode', () => { window.dev = true - onRouteUpdate({}) + onRouteUpdate({}, {}) expect(window._paq.push).toHaveBeenCalledTimes(1) }) }) @@ -43,19 +43,19 @@ describe('gatsby-plugin-matomo', () => { it('does not send page view when _paq is undefined', () => { delete window._paq - onRouteUpdate({}) + onRouteUpdate({}, {}) jest.runAllTimers() expect(setTimeout).not.toHaveBeenCalled() }) it('sends page view', () => { - onRouteUpdate({}) + onRouteUpdate({}, {}) jest.runAllTimers() expect(window._paq.push).toHaveBeenCalledTimes(5) }) it('uses setTimeout with a minimum delay of 32ms', () => { - onRouteUpdate({}) + onRouteUpdate({}, {}) jest.runAllTimers() expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 32) expect(window._paq.push).toHaveBeenCalledTimes(5) diff --git a/src/gatsby-browser.js b/src/gatsby-browser.js index 57cd3ed..790c05d 100644 --- a/src/gatsby-browser.js +++ b/src/gatsby-browser.js @@ -22,9 +22,7 @@ export const onRouteUpdate = ({ location, prevLocation }, pluginOptions) => { prevLocation && prevLocation.pathname + prevLocation.search + prevLocation.hash - const { - trackLoad = true - } = pluginOptions + const { trackLoad = true } = pluginOptions // document.title workaround stolen from: // https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-google-analytics/src/gatsby-browser.js @@ -51,7 +49,13 @@ export const onRouteUpdate = ({ location, prevLocation }, pluginOptions) => { first = false if (trackLoad) { - _paq.push(['trackEvent', 'javascript', 'load', 'duration', getDuration()]) + _paq.push([ + 'trackEvent', + 'javascript', + 'load', + 'duration', + getDuration() + ]) } if (dev) {