#My Jest Config
1 messages · Page 1 of 1 (latest)
// jest.setup.js
import '@testing-library/jest-dom';
import { toHaveNoViolations } from 'jest-axe';
import { toHaveStyle } from '@testing-library/jest-dom';
expect.extend(toHaveNoViolations, toHaveStyle);```
// jest.config.js
const nextJest = require('next/jest');
const createJestConfig = nextJest({
dir: './',
verbose: true,
});
// Add any custom config to be passed to Jest
const customJestConfig = nextJest({
clearMocks: true,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.json',
enableTsDiagnostics: true,
},
},
testEnvironment: 'jsdom',
collectCoverage: true,
rootDir: './src',
collectCoverageFrom: ['<rootDir>/src/**/*.{js,jsx,ts,tsx}'],
coverageReporters: ['lcov', 'text', 'html'],
coverageDirectory: '<rootDir>/test-coverage/',
moduleDirectories: ['node_modules', '<rootDir>'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { configFile: './.babelrc' }],
},
moduleNameMapper: {
'\\.(css|less|scss|sss|styl)$': './node_modules/jest-css-modules',
},
coveragePathIgnorePatterns: ['<rootDir>/test/test-utils.js'],
coverageThreshold: {
// set coverage threshold for each file
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1',
database: '<rootDir>/src/utils/database',
},
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/(?!@foo)'],
});
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);