-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
30 lines (27 loc) · 1.24 KB
/
vitest.setup.ts
File metadata and controls
30 lines (27 loc) · 1.24 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
import '@angular/compiler';
import { TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { beforeEach } from 'vitest';
// Provide minimal DOM polyfill for Angular's platform factory (tests run in Node without jsdom)
if (typeof globalThis.document === 'undefined') {
(globalThis as any).document = {
createElement: () => ({ setAttribute: () => {}, appendChild: () => {}, style: {} }),
createComment: () => ({}),
querySelector: () => null,
querySelectorAll: () => [],
body: { appendChild: () => {}, removeChild: () => {} },
head: { appendChild: () => {}, querySelector: () => null },
documentElement: { setAttribute: () => {} },
createTextNode: () => ({}),
addEventListener: () => {},
removeEventListener: () => {},
createDocumentFragment: () => ({ appendChild: () => {} }),
implementation: { createHTMLDocument: () => (globalThis as any).document },
};
}
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false },
});
beforeEach(() => {
TestBed.resetTestingModule();
});