Sha256: e2d7120c9efe4b0c4acc9b3c8a5908030179ec5d727b6f51b4fa32699c2f1317
Contents?: true
Size: 1.81 KB
Versions: 25
Compression:
Stored size: 1.81 KB
Contents
describe("GOVUK.analyticsPlugins.error", function() { 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
25 entries across 25 versions & 1 rubygems