Files
notifications-admin/tests/javascripts/errorBanner.test.js
Leo Hemsted c96a1dc0b7 add new error banner module for showing users js errors
this ensures it's reusable by other components, and easier to unit test
by isolating the separate concerns

note: this is not in Modules since that's designed for classes that are
then bound to an element in the DOM as indicated by a data-module
attribute. This will just live at the window.GOVUK level since we want
there to only ever be one `.banner-dangerous` warning.
2021-09-14 18:43:25 +01:00

42 lines
1.2 KiB
JavaScript

beforeAll(() => {
require('../../app/assets/javascripts/errorBanner.js')
});
afterAll(() => {
require('./support/teardown.js');
});
describe("Error Banner", () => {
afterEach(() => {
document.body.innerHTML = '';
});
describe("The `hideBanner` method", () => {
test("Will hide the element", () => {
document.body.innerHTML = `
<span class="govuk-error-message banner-dangerous js-error-visible">
</span>`;
window.GOVUK.ErrorBanner.hideBanner();
expect(document.querySelector('.banner-dangerous').classList).toContain('govuk-!-display-none')
});
});
describe("The `showBanner` method", () => {
beforeEach(() => {
document.body.innerHTML = `
<span class="govuk-error-message banner-dangerous js-error-visible govuk-!-display-none">
</span>`;
window.GOVUK.ErrorBanner.showBanner('Some Err');
});
test("Will set a specific error message on the element", () => {
expect(document.querySelector('.banner-dangerous').textContent).toEqual('Error: Some Err')
});
test("Will show the element", () => {
expect(document.querySelector('.banner-dangerous').classList).not.toContain('govuk-!-display-none')
});
});
});