-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
35 lines (27 loc) · 1.13 KB
/
Copy pathvitest.setup.ts
File metadata and controls
35 lines (27 loc) · 1.13 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
import {ResizeObserver} from '@juggle/resize-observer';
import * as matchers from '@testing-library/jest-dom/matchers';
import {cleanup} from '@testing-library/react';
import {afterEach, beforeAll, beforeEach, expect} from 'vitest';
import {resetUniqueIdCount, setUniqueSeed} from '@workday/canvas-kit-react/common';
import {verifyComponent} from './test-utils/verifyComponent';
expect.extend(matchers);
// add convenience variables to the global context
(globalThis as any).verifyComponent = verifyComponent;
// Not necessary for our tests, but demonstrate how to have stable ids for vitest snapshots
beforeEach(() => {
setUniqueSeed('a');
resetUniqueIdCount();
});
beforeAll(() => {
// jsdom doesn't have a ResizeObserver. Use a polyfill: https://github.com/jsdom/jsdom/issues/3368
globalThis.ResizeObserver = ResizeObserver;
// SSR tests don't have HTMLElement defined, but render() tests do, so we have to conditionally
// polyfill the HTMLElement
if (typeof HTMLElement !== 'undefined') {
// eslint-disable-next-line no-empty-function
HTMLElement.prototype.scrollIntoView = () => {};
}
});
afterEach(() => {
cleanup();
});