Open
Description
@testing-library/react
version: 13.2.0- Testing Framework and version: jest 28.1.0
- DOM Environment: "jest-environment-jsdom": "^28.1.0", "react": "^18.1.0",
Relevant code or config:
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import Stack from '../Stack';
describe('Stack', () => {
it('renders', () => {
const stack = render(<Stack />);
const button = stack.getByRole('button');
expect(button).toBeInTheDocument();
});
});
jest.setup.js:
import '@testing-library/jest-dom/extend-expect';
jest.config.js:
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
rootDir: '.',
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i': `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
'^~/(.*)$': '<rootDir>/$1',
},
collectCoverageFrom: ['**/*.{js,jsx,ts,tsx}', '!**/*.d.ts', '!**/node_modules/**'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/', '<rootDir>/functions'],
testEnvironment: 'jsdom',
verbose: false,
resolver: 'jest-node-exports-resolver',
transform: { '\\.m?[jt]sx?$': ['babel-jest', { presets: ['next/babel'] }] },
transformIgnorePatterns: ['/node_modules/(?!(dequal)/)', '^.+\\.module\\.(css|sass|scss)$'],
};
What you did:
yarn add jest@latest ts-jest@latest -D
yarn add @testing-library/dom -D
yarn add jest-environment-jsdom -D
yarn test Stack
What happened:
Before I upgraded my tests were passing. Now they all fail
FAIL components/__tests__/Stack.unit.test.tsx
● Test suite failed to run
Cannot find module '@jest/expect' from 'node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js'
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:491:11)
Metadata
Metadata
Assignees
Labels
No labels