-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
63 lines (55 loc) · 1.81 KB
/
Copy pathvitest.setup.ts
File metadata and controls
63 lines (55 loc) · 1.81 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import '@testing-library/jest-dom'
import { beforeAll, vi } from 'vitest'
import { setProjectAnnotations } from '@storybook/react'
import * as projectAnnotations from './.storybook/preview'
import { configure } from '@testing-library/react'
// Configure testing library to reduce verbose output
configure({
testIdAttribute: 'data-testid',
getElementError: (message, container) => {
const error = new Error(message || 'Element not found')
error.name = 'TestingLibraryElementError'
return error
}
})
// Mock deprecated Storybook testing utilities for legacy stories
vi.mock('@storybook/testing-library', () => ({
within: vi.fn(),
userEvent: vi.fn(),
screen: vi.fn(),
expect: vi.fn()
}))
vi.mock('@storybook/jest', () => ({
expect: vi.fn(),
jest: vi.fn()
}))
// Suppress React warnings in tests
const originalConsoleWarn = console.warn
const originalConsoleError = console.error
// Apply Storybook's global decorators and parameters
const project = setProjectAnnotations([projectAnnotations])
beforeAll(() => {
// Suppress specific React warnings during tests but preserve test failures
console.warn = (message, ...args) => {
// Skip React warnings during tests
if (
typeof message === 'string' &&
(message.includes('Warning:') || message.includes('React Warning:') || message.includes('validateDOMNesting'))
) {
return
}
originalConsoleWarn(message, ...args)
}
console.error = (message, ...args) => {
// Skip React warnings during tests but preserve real errors
if (
typeof message === 'string' &&
(message.includes('Warning:') || message.includes('React Warning:') || message.includes('validateDOMNesting'))
) {
return
}
originalConsoleError(message, ...args)
}
// Run the existing Storybook setup
return project.beforeAll?.()
})