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

Version Path
govuk_frontend_toolkit-8.2.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-8.1.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-8.0.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.6.0 app/assets/spec/unit/analytics/error-tracking.spec.js
idsk_frontend_toolkit-8.4.4 app/assets/spec/unit/analytics/error-tracking.spec.js
idsk_frontend_toolkit-7.4.3 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.5.0 app/assets/spec/unit/analytics/error-tracking.spec.js
idsk_frontend_toolkit-7.4.2 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.4.2 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.4.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.4.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.3.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.2.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.1.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.0.1 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-7.0.0 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-6.0.4 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-6.0.3 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-6.0.2 app/assets/spec/unit/analytics/error-tracking.spec.js
govuk_frontend_toolkit-6.0.1 app/assets/spec/unit/analytics/error-tracking.spec.js