Problems with mount in enzyme

22 Views Asked by At

I'm trying to write a snapshot test for my page, but it won't even create the snapshot. This is the error I get when I try to write my test:

"Conversion of type 'RegExp' to type 'QuestionsP' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'RegExp' is missing the following properties from type 'QuestionsP': questions, showUnanswered, tags, searchSuggestions, and 11 more."

My test:

import * as React from "react";
import QuestionsP from "../src/pages/Questions";
import { render, shallow, mount, ReactWrapper } from "enzyme";

describe("Questions Component", () => {
  test("renders Questions component", (done) => {
    const wrapper = mount(<QuestionsP />)

    setTimeout(() => {
     expect(wrapper).toMatchSnapshot();
     done();
    });
  });
});

My package.json dependencies:

"dependencies": {
  "@popperjs/core": "^2.11.8",
  "axios": "^1.5.0",
  "bootstrap": "^5.3.1",
  "bootstrap-icons": "^1.11.1",
  "css-loader": "^6.8.1",
  "jquery": "^3.7.1",
  "react-bulma-components": "^4.1.0",
  "react-popper": "^2.3.0",
  "react-router-dom-v5-compat": "^6.16.0",
  "react-simplified": "^4.0.1",
  "style-loader": "^3.3.3"
},
"devDependencies": {
  "@babel/core": "^7.22.17",
  "@babel/preset-env": "^7.22.15",
  "@babel/preset-react": "^7.22.15",
  "@babel/preset-typescript": "^7.22.15",
  "@cfaester/enzyme-adapter-react-18": "^0.7.1",
  "@testing-library/jest-dom": "^6.1.4",
  "@testing-library/react": "^14.1.2",
  "@types/enzyme": "^3.10.16",
  "@types/jest": "^29.5.4",
  "@types/react-dom": "^18.2.7",
  "@types/react-router-dom": "^5.3.3",
  "babel-jest": "^29.7.0",
  "babel-loader": "^9.1.3",
  "enzyme": "^3.11.0",
  "enzyme-to-json": "^3.6.2",
  "jest": "^29.7.0",
  "jest-environment-jsdom": "^29.7.0",
  "prettier": "^3.0.3",
  "react-test-renderer": "^18.2.0",
  "typescript": "^5.2.2",
  "webpack": "^5.88.2",
  "webpack-cli": "^5.1.4"
}

I was expecting a snapshot of my React component.

0

There are 0 best solutions below