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

Version Path
govuk_frontend_toolkit-4.18.3 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.18.2 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.18.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.18.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.17.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.16.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.16.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.15.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.14.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.14.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.13.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.12.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.11.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.10.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.9.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.9.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.8.2 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.8.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.8.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-4.7.0 app/assets/spec/unit/analytics/error-tracking.spec.js