mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 03:58:25 -04:00
Merge pull request #3087 from alphagov/add-js-tests-for-error-tracking
Add tests for error tracking module
This commit is contained in:
36
tests/javascripts/errorTracking.test.js
Normal file
36
tests/javascripts/errorTracking.test.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 = '';
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("It should send the right data to Google Analytics", () => {
|
||||||
|
|
||||||
|
window.ga = jest.fn(() => {});
|
||||||
|
|
||||||
|
// start the module
|
||||||
|
window.GOVUK.modules.start();
|
||||||
|
|
||||||
|
expect(window.ga).toHaveBeenCalled();
|
||||||
|
expect(window.ga.mock.calls[0]).toEqual(['send', 'event', 'Error', 'validation', 'missing field']);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user