Cannot find module '@testing-library/jest-dom/extend-expect'
dep opened this issue · comments
Danny Peck commented
What you did:
I updated @testing-library/jest-dom
from "5.16.5"
to "6.1.2"
and get the following error:
Cannot find module '@testing-library/jest-dom/extend-expect'
Has this changed since 6x? Can't find documentation around it.
Danny Peck commented
Inspecting node_modules/@testing-library/jest-dom
before and after the update, it does look lik extend-expect.js
was removed. What's the right way to include this?
Example of what I was doing with 5x
import * as React from "react";
import "regenerator-runtime/runtime";
import { cleanup, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { ThemeProvider } from "@mui/material";
import { theme } from "../../theme";
import { Logo } from "./Logo";
describe("Logo", () => {
afterEach(cleanup);
beforeEach(() => {
render(
<ThemeProvider theme={theme}>
<Logo url="http://google.com" />
</ThemeProvider>
);
});
test("renders the component", () => {
expect(screen.getByTestId("logo")).toBeTruthy();
});
});
Danny Peck commented
I was able to fix this by adding the following to my jest.setup
:
const matchers = require("jest-extended");
expect.extend(matchers);
afterEach(() => {
jest.useRealTimers();
});
Including this devDependency
"jest-extended": "4.0.1",
And replacing all instances of:
import "@testing-library/jest-dom/extend-expect";
with
import "@testing-library/jest-dom";
👍🏻