Skip to content

Commit 5daf5fb

Browse files
Add tests for automatic initialisation
1 parent 1d32e4d commit 5daf5fb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/nhsuk.jsdom.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { waitFor } from '@testing-library/dom'
2+
3+
import { initAll } from './index.js'
4+
5+
jest.mock('./index.js')
6+
7+
describe('NHS.UK frontend', () => {
8+
describe('Automatic initialisation', () => {
9+
it('should init components on DOMContentLoaded', async () => {
10+
await import('./nhsuk.js')
11+
12+
// Should not initialise on import
13+
expect(initAll).not.toHaveBeenCalled()
14+
15+
// Should initialise on DOMContentLoaded
16+
window.document.dispatchEvent(new Event('DOMContentLoaded'))
17+
await waitFor(() => expect(initAll).toHaveBeenCalled())
18+
})
19+
})
20+
})

0 commit comments

Comments
 (0)