mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-18 12:07:01 +08:00
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import '@testing-library/jest-dom/vitest'
|
|
import { cleanup } from '@testing-library/react'
|
|
import { afterEach, vi } from 'vitest'
|
|
|
|
afterEach(() => cleanup())
|
|
|
|
function createMemoryStorage(): Storage {
|
|
const values = new Map<string, string>()
|
|
return {
|
|
get length() {
|
|
return values.size
|
|
},
|
|
clear: () => values.clear(),
|
|
getItem: (key) => values.get(key) ?? null,
|
|
key: (index) => Array.from(values.keys())[index] ?? null,
|
|
removeItem: (key) => {
|
|
values.delete(key)
|
|
},
|
|
setItem: (key, value) => {
|
|
values.set(key, String(value))
|
|
}
|
|
}
|
|
}
|
|
|
|
Object.defineProperty(globalThis, 'localStorage', {
|
|
configurable: true,
|
|
value: createMemoryStorage()
|
|
})
|
|
|
|
Object.defineProperty(globalThis, 'sessionStorage', {
|
|
configurable: true,
|
|
value: createMemoryStorage()
|
|
})
|
|
|
|
Object.defineProperty(globalThis.URL, 'createObjectURL', {
|
|
configurable: true,
|
|
value: vi.fn(() => 'blob:wxe-test-audio')
|
|
})
|
|
|
|
Object.defineProperty(globalThis.URL, 'revokeObjectURL', {
|
|
configurable: true,
|
|
value: vi.fn()
|
|
})
|