“Cannot find module @testing-library/jest-dom from jest-setup.jsâ€
Unanswered
Araucanian herring posted this in #help-forum
Araucanian herringOP
Trying to do testing with jest and jest-dom, both of them are installed. However I get “Cannot find module @testing-library/jest-dom†when trying to do a simple test in index.test.jsx
I also have jest-setup.js where I import
In my jest.config.js I have specified setupFilesAfterEnv.
jest.config.mjs
index.test.jsx
How can i solve it?
Thanks in Advance
I also have jest-setup.js where I import
import '@testing-library/jest-dom/extend-expect';In my jest.config.js I have specified setupFilesAfterEnv.
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],jest.config.mjs
import nextJest from 'next/jest.js'
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const config = {
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testEnvironment: 'jest-environment-jsdom',
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config)index.test.jsx
import '@testing-library/jest-dom';
describe("hello" , () => {
it("hello", () => {});
})How can i solve it?
Thanks in Advance
1 Reply
Western Bluebird
Hi, I'm facing the same proble, did you solve it?