mirror of
https://github.com/kremalicious/gatsby-plugin-matomo.git
synced 2024-12-22 17:23:23 +01:00
onRouteUpdate test tweaks
This commit is contained in:
parent
d64e7ffbbc
commit
5871f667b9
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user