Tooling@accelint/vitest-config
dom
Vitest configuration for React components and DOM testing
Vitest configuration preset for testing React components and DOM-dependent code. Extends the base configuration with React plugin support.
Usage
import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/dom';
export default mergeConfig(
baseConfig,
defineConfig({
test: {
globals: true,
environment: 'jsdom',
},
}),
);Reference
export default mergeConfig(
base,
defineConfig({
plugins: [react()],
}),
);The DOM configuration merges the no-dom base configuration with the React plugin from @vitejs/plugin-react.
Included Plugins
| Plugin | Purpose |
|---|---|
@vitejs/plugin-react | Enables React Fast Refresh and JSX transformation |
vite-tsconfig-paths | Resolves TypeScript path aliases (inherited from base) |
Configuration Settings
All settings from no-dom plus:
- React Fast Refresh for component hot reloading
- JSX transformation for
.tsxfiles - Automatic React import injection
Examples
Example: Simple re-export
For projects that don't need custom configuration:
// vitest.config.ts
export { default } from '@accelint/vitest-config/dom';Example: React component testing with jsdom
import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/dom';
export default mergeConfig(
baseConfig,
defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./tests/setup.ts'],
},
}),
);Example: Adding custom React plugin options
import react from '@vitejs/plugin-react';
import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/no-dom';
// Use no-dom as base and add React with custom options
export default mergeConfig(
baseConfig,
defineConfig({
plugins: [
react({
jsxRuntime: 'automatic',
babel: {
plugins: ['babel-plugin-styled-components'],
},
}),
],
}),
);Example: Component test with React Testing Library
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { Button } from './Button';
describe('Button', () => {
it('renders children correctly', () => {
render(<Button>Click me</Button>);
expect(screen.getByRole('button')).toHaveTextContent('Click me');
});
});Good to know: The DOM configuration inherits all settings from the no-dom base configuration, including coverage, TypeScript paths, and mock behavior. Use this preset when testing React components or browser APIs.
Related
- no-dom - Base Vitest configuration without React
- mockBroadcastChannel - Mock for BroadcastChannel API