mirror of
https://github.com/kremalicious/gatsby-plugin-matomo.git
synced 2024-12-22 09:13:19 +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', () => {
|
it('does not send page view', () => {
|
||||||
onRouteUpdate({})
|
onRouteUpdate({}, {})
|
||||||
expect(window._paq.push).not.toHaveBeenCalled()
|
expect(window._paq.push).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends page view in dev mode', () => {
|
it('sends page view in dev mode', () => {
|
||||||
window.dev = true
|
window.dev = true
|
||||||
onRouteUpdate({})
|
onRouteUpdate({}, {})
|
||||||
expect(window._paq.push).toHaveBeenCalledTimes(1)
|
expect(window._paq.push).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -43,19 +43,19 @@ describe('gatsby-plugin-matomo', () => {
|
|||||||
|
|
||||||
it('does not send page view when _paq is undefined', () => {
|
it('does not send page view when _paq is undefined', () => {
|
||||||
delete window._paq
|
delete window._paq
|
||||||
onRouteUpdate({})
|
onRouteUpdate({}, {})
|
||||||
jest.runAllTimers()
|
jest.runAllTimers()
|
||||||
expect(setTimeout).not.toHaveBeenCalled()
|
expect(setTimeout).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends page view', () => {
|
it('sends page view', () => {
|
||||||
onRouteUpdate({})
|
onRouteUpdate({}, {})
|
||||||
jest.runAllTimers()
|
jest.runAllTimers()
|
||||||
expect(window._paq.push).toHaveBeenCalledTimes(5)
|
expect(window._paq.push).toHaveBeenCalledTimes(5)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('uses setTimeout with a minimum delay of 32ms', () => {
|
it('uses setTimeout with a minimum delay of 32ms', () => {
|
||||||
onRouteUpdate({})
|
onRouteUpdate({}, {})
|
||||||
jest.runAllTimers()
|
jest.runAllTimers()
|
||||||
expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 32)
|
expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 32)
|
||||||
expect(window._paq.push).toHaveBeenCalledTimes(5)
|
expect(window._paq.push).toHaveBeenCalledTimes(5)
|
||||||
|
@ -22,9 +22,7 @@ export const onRouteUpdate = ({ location, prevLocation }, pluginOptions) => {
|
|||||||
prevLocation &&
|
prevLocation &&
|
||||||
prevLocation.pathname + prevLocation.search + prevLocation.hash
|
prevLocation.pathname + prevLocation.search + prevLocation.hash
|
||||||
|
|
||||||
const {
|
const { trackLoad = true } = pluginOptions
|
||||||
trackLoad = true
|
|
||||||
} = pluginOptions
|
|
||||||
|
|
||||||
// document.title workaround stolen from:
|
// document.title workaround stolen from:
|
||||||
// https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-google-analytics/src/gatsby-browser.js
|
// 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
|
first = false
|
||||||
|
|
||||||
if (trackLoad) {
|
if (trackLoad) {
|
||||||
_paq.push(['trackEvent', 'javascript', 'load', 'duration', getDuration()])
|
_paq.push([
|
||||||
|
'trackEvent',
|
||||||
|
'javascript',
|
||||||
|
'load',
|
||||||
|
'duration',
|
||||||
|
getDuration()
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
|
Loading…
Reference in New Issue
Block a user