Sha256: 33eafd6d4bfbc8ee4d763682eea3077ccf8b25145a71436d7671d80f382248fe
Contents?: true
Size: 1.9 KB
Versions: 31
Compression:
Stored size: 1.9 KB
Contents
/* global describe it expect beforeEach afterEach spyOn */ describe('GOVUK.analyticsPlugins.error', function () { 'use strict' var GOVUK = window.GOVUK GOVUK.analyticsPlugins.error({filenameMustMatch: /gov\.uk/}) beforeEach(function () { GOVUK.analytics = {trackEvent: function () {}} spyOn(GOVUK.analytics, 'trackEvent') }) afterEach(function () { delete GOVUK.analytics }) it('sends errors to Google Analytics', function () { triggerError('https://www.gov.uk/filename.js', 2, 'Error message') expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( 'JavaScript Error', 'Error message', { label: 'https://www.gov.uk/filename.js: 2', value: 1, nonInteraction: true }) }) it('tracks only errors with a matching or blank filename', function () { triggerError('http://www.gov.uk/somefile.js', 2, 'Error message') triggerError('', 2, 'In page error') triggerError('http://www.broken-external-plugin-site.com/horrible.js', 2, 'Error message') expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( 'JavaScript Error', 'Error message', { label: 'http://www.gov.uk/somefile.js: 2', value: 1, nonInteraction: true }) expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( 'JavaScript Error', 'In page error', { label: ': 2', value: 1, nonInteraction: true }) expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( 'JavaScript Error', 'Error message', { label: 'http://www.broken-external-plugin-site.com/horrible.js: 2', value: 1, nonInteraction: true }) }) function triggerError (filename, lineno, message) { var event = document.createEvent('Event') event.initEvent('error', true, true) event.filename = filename event.lineno = lineno event.message = message window.dispatchEvent(event) } })
Version data entries
31 entries across 31 versions & 2 rubygems