generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.ts
More file actions
40 lines (34 loc) · 1.27 KB
/
jest.setup.ts
File metadata and controls
40 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// https://nextjs.org/docs/app/building-your-application/testing/jest#optional-extend-jest-with-custom-matchers
import '@testing-library/jest-dom';
import { TextEncoder, TextDecoder } from 'node:util';
import { createMocks } from 'react-idle-timer';
/*
* Polyfill for fetch API which includes the Request object
* this helps solve the issue of the test throwing an error if the `getAmplifyBackendClient` is not mocked out.
* https://github.com/vercel/next.js/discussions/59041#discussioncomment-10043081
*/
import 'whatwg-fetch';
/*
* Polyfill for TextDecoder and TextEncoder
* https://github.com/jsdom/jsdom/issues/2524
*/
Object.assign(global, { TextDecoder, TextEncoder });
/*
* Polyfill for structuredClone.
* amplify/nextjs-adapter uses this in createRunWithAmplifyServerContext by importing GlobalSettings.
* https://github.com/jsdom/jsdom/issues/3363
*/
Object.assign(global, {
// eslint-disable-next-line unicorn/prefer-structured-clone
structuredClone: (val: unknown) => JSON.parse(JSON.stringify(val)),
});
/*
* Create mocks for react-idle-timer
*/
createMocks();
// set feature flag
process.env.NEXT_PUBLIC_ENABLE_PROOFING = 'true';
// mock unimplemented scrollIntoView
if (typeof window !== 'undefined') {
window.HTMLElement.prototype.scrollIntoView = jest.fn();
}