-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
36 lines (32 loc) · 1011 Bytes
/
jest.setup.ts
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
import { db } from '@/nostr/db'
import { vi } from 'vitest'
// https://github.com/vitest-dev/vitest/issues/4043#issuecomment-1905172846
class ESBuildAndJSDOMCompatibleTextEncoder extends TextEncoder {
constructor() {
super()
}
encode(input: string) {
if (typeof input !== 'string') {
throw new TypeError('`input` must be a string')
}
const decodedURI = decodeURIComponent(encodeURIComponent(input))
const arr = new Uint8Array(decodedURI.length)
const chars = decodedURI.split('')
for (let i = 0; i < chars.length; i++) {
arr[i] = decodedURI[i].charCodeAt(0)
}
return arr
}
}
global.TextEncoder = ESBuildAndJSDOMCompatibleTextEncoder
vi.mock('nostr-tools', async () => {
const originalModule = await vi.importActual<Record<string, unknown>>('nostr-tools')
return {
...originalModule,
verifyEvent: vi.fn(() => true),
}
})
vi.mock('constants/relays')
vi.mock('core/operators/verifyWorker')
// Reset Indexeddb
beforeEach(() => db.clearDB())