Skip to content

Commit 8fa4e8e

Browse files
author
Loïc Mangeonjean
committed
fix: update tests
1 parent 79f5538 commit 8fa4e8e

File tree

5 files changed

+233
-342
lines changed

5 files changed

+233
-342
lines changed

browserMock.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs/promises'
22
import { performance } from 'perf_hooks'
3+
import { fetch as fetchPolyfill } from 'whatwg-fetch'
34

45
Object.defineProperty(document, 'queryCommandSupported', {
56
value: jest.fn().mockImplementation(() => true),
@@ -22,12 +23,16 @@ Object.defineProperty(window, 'matchMedia', {
2223
});
2324

2425
Object.defineProperty(window, 'fetch', {
25-
value: jest.fn(async (url) => {
26-
const content = await fs.readFile(new URL(url).pathname)
27-
return {
28-
json: async () => JSON.stringify(JSON.parse(content.toString())),
29-
arrayBuffer: async () => content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength),
30-
status: 200
26+
value: jest.fn(async (url, options) => {
27+
if (url.startsWith('file:')) {
28+
const content = await fs.readFile(new URL(url).pathname)
29+
return {
30+
json: async () => JSON.stringify(JSON.parse(content.toString())),
31+
arrayBuffer: async () => content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength),
32+
status: 200
33+
}
34+
} else {
35+
return fetchPolyfill(url, options)
3136
}
3237
})
3338
})

0 commit comments

Comments
 (0)