Open sedatbasar opened 1 month ago
Example files from test-utils.tsx
import React from 'react'
import { render } from '@testing-library/react'
import { MockedProvider, MockedResponse } from '@apollo/client/testing'
type Options = {
mocks?: MockedResponse[]
}
const renderWithProviders = (ui: React.ReactElement, options: Options = {}) => {
render(
<MockedProvider mocks={options.mocks} addTypename={false}>
{ui}
</MockedProvider>
)
}
export * from '@testing-library/react'
export { renderWithProviders as render }
export { userEvent } from '@testing-library/user-event'
eslintrc
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "@testing-library/react",
"importNames": ["*"],
"message": "Use the imports from @/__tests__/test-utils instead!"
}
]
}
]
vitest.setup.ts
/// <reference types="vitest" />
import '@testing-library/jest-dom/vitest'
vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import { fileURLToPath } from 'node:url'
export default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom',
setupFiles: ['./__tests__/utils/vitest.setup.ts']
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./', import.meta.url))
}
}
})
Background:
AC: