2019-08-12 16:48:23 +01:00
|
|
|
beforeAll(() => {
|
|
|
|
|
require('../../app/assets/javascripts/errorTracking.js');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
|
require('./support/teardown.js');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Error tracking', () => {
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
|
|
|
|
// set up DOM
|
|
|
|
|
document.body.innerHTML = `<div data-module="track-error" data-error-type="validation" data-error-label="missing field"></div>`;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
|
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-15 14:40:48 +00:00
|
|
|
test("It should send the right data to Google Analytics", () => {
|
2019-08-12 16:48:23 +01:00
|
|
|
|
2020-01-15 14:40:48 +00:00
|
|
|
window.ga = jest.fn(() => {});
|
2019-08-12 16:48:23 +01:00
|
|
|
|
|
|
|
|
// start the module
|
|
|
|
|
window.GOVUK.modules.start();
|
|
|
|
|
|
2020-01-15 14:40:48 +00:00
|
|
|
expect(window.ga).toHaveBeenCalled();
|
|
|
|
|
expect(window.ga.mock.calls[0]).toEqual(['send', 'event', 'Error', 'validation', 'missing field']);
|
2019-08-12 16:48:23 +01:00
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|