Files
notifications-admin/tests/javascripts/errorTracking.test.js

42 lines
957 B
JavaScript
Raw Normal View History

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 = '';
2025-08-07 16:49:14 -04:00
delete window.NotifyModules.analytics;
2019-08-12 16:48:23 +01:00
});
2025-08-07 16:49:14 -04:00
test("If there is an analytics tracker set up, it should send details of the error to window.NotifyModules.analytic", () => {
2019-08-12 16:48:23 +01:00
2025-08-07 16:49:14 -04:00
window.NotifyModules.analytics = {
'trackEvent': jest.fn()
};
2019-08-12 16:48:23 +01:00
// start the module
2025-08-07 16:49:14 -04:00
window.NotifyModules.start();
2019-08-12 16:48:23 +01:00
2025-08-07 16:49:14 -04:00
expect(window.NotifyModules.analytics.trackEvent).toHaveBeenCalled();
expect(window.NotifyModules.analytics.trackEvent.mock.calls[0]).toEqual(['Error', 'validation', {
'label': 'missing field'
}]);
2019-08-12 16:48:23 +01:00
});
});