-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
40 lines (34 loc) · 1.01 KB
/
vitest.setup.ts
File metadata and controls
40 lines (34 loc) · 1.01 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
31
32
33
34
35
36
37
38
39
40
/**
* Shared Vitest setup file for the testing package.
*
* Import this in your vitest.config.ts to get common mocks and setup.
*
* @example
* ```ts
* // vitest.config.ts
* export default defineConfig({
* test: {
* setupFiles: ['@sim/testing/setup'],
* },
* })
* ```
*/
import { afterEach, beforeEach, vi } from 'vitest'
import { setupGlobalFetchMock } from '../mocks/fetch.mock'
import { createMockLogger } from '../mocks/logger.mock'
import { clearStorageMocks, setupGlobalStorageMocks } from '../mocks/storage.mock'
// Setup global storage mocks
setupGlobalStorageMocks()
// Setup global fetch mock with empty JSON response by default
setupGlobalFetchMock({ json: {} })
// Clear mocks between tests
beforeEach(() => {
vi.clearAllMocks()
})
afterEach(() => {
clearStorageMocks()
})
// Export utilities for use in tests
export { createMockLogger }
export { setupGlobalStorageMocks, clearStorageMocks }
export { mockFetchError, mockNextFetchResponse, setupGlobalFetchMock } from '../mocks/fetch.mock'