-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.js
More file actions
40 lines (36 loc) · 824 Bytes
/
vitest.setup.js
File metadata and controls
40 lines (36 loc) · 824 Bytes
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
import { server } from "./test/server.js";
// Very simple mock of XmlHttpRequest with only the parts we use
class MockXmlHttpRequest extends EventTarget {
open() {}
send(file) {
this.upload.dispatchEvent(new Event("progress"));
if (!this.aborted) {
this.onreadystatechange?.();
this.onload?.(file);
}
}
abort() {
this.aborted = true;
this.dispatchEvent(new Event("abort"));
this.onabort();
}
setRequestHeader() {}
getResponseHeader(header) {
return header;
}
upload = new EventTarget();
aborted = false;
timeout = 0;
readyState = 4;
status = 200;
}
beforeAll(() => {
server.listen({ onUnhandledRequest: "error" });
global.XMLHttpRequest = MockXmlHttpRequest;
});
afterAll(() => {
server.close();
});
afterEach(() => {
server.resetHandlers();
});