The 'toMatchSnapshot' property is not found on the 'Assertion' data type

While constructing a web app using CRA with Typescript and Jest for testing, I've encountered an unexpected error message

'Property 'toMatchSnapshot' does not exist on type 'Assertion'.
during all snapshot tests.

Here's an example of a test where this error occurs:

import { BrowserRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';


describe('<Button />', () => {
  test('Button should render with mandatory props', () => {
    const tree = renderer
      .create(
        <BrowserRouter>
          <Button text="Test Text" />
        </BrowserRouter>
      )
      .toJSON();
    expect(tree).toMatchSnapshot(); <-- Error here
  });
}

I've attempted various solutions like updating Jest, as well as related packages, but none have resolved the issue.

My Package.json:

{
  "name": "webapp",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "start": "react-scripts start",
    "cypress:open": "cypress open"
  },
  "dependencies": {
    "@babel/core": "^7.19.1",
    "@babel/plugin-syntax-flow": "^7.18.6",
    "@babel/plugin-transform-react-jsx": "^7.19.0",
    "@react-spring/web": "^9.5.5",
    "@types/socket.io-client": "^3.0.0",
    "axios": "^0.27.2",
    "formik": "^2.2.9",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-error-boundary": "^3.1.4",
    "react-router-dom": "^6.4.3",
    "react-scripts": "^5.0.1",
    "socket.io-client": "^4.5.1",
    "uuid": "^9.0.0",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^13.0.3",
    "@bahmutov/cypress-esbuild-preprocessor": "^2.1.5",
    "@types/cypress-cucumber-preprocessor": "^4.0.1",
    "@types/jest": "^29.0.3",
    "@types/react": "^18.0.15",
    "@types/react-dom": "^18.0.6",
    "@types/react-test-renderer": "^18.0.0",
    "autoprefixer": "^10.4.7",
    "cypress": "^10.11.0",
    "eslint": "^8.20.0",
    "jest": "^29.0.3",
    "jest-environment-jsdom": "^29.1.2",
    "postcss": "^8.4.14",
    "react-test-renderer": "^18.2.0",
    "tailwindcss": "^3.1.6",
    "ts-jest": "^29.0.1",
    "typescript": "^4.8.3"
  },
  "jest": {
    "clearMocks": true,
    "transform": {
      "^.+\\.(ts|tsx|js|jsx)$": "ts-jest"
    },
    "testEnvironment": "jsdom"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "stepDefinitions": "cypress/e2e/**/*.ts"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Answer №1

It appears that there is an issue with the compatibility between your Cypress and Jest installations. For more details, you may refer to this Stack Overflow thread: Cypress causing type errors in jest assertions

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can be taken to effectively build a test suite architecture using Jest?

After exploring all the available resources on the Jest documentation website, including various guides and examples, I have yet to find a solution to my specific question. I am in search of a methodology that would enable me to individually run test case ...

Refresh the html content of the parent element using javascript

Is there a way to change the innerHTML of a div tag located within the parent window from inside an iframe? How can I access the parent window in this scenario? ...

I encountered difficulties installing Jest on my computer due to gyp errors

I've been attempting to set up Jest on my system using npm install --save dev @types/jest Encountering the following errors: npm install --save dev @types/jest npm notice npm notice New minor version of npm available! 9.5.0 -> 9.6.0 npm notice Ch ...

Creating Custom Coupons Using Vue.js for Print Outputs

I've been struggling to print a specific div, even though it seems like a simple task, it's turning out to be quite challenging. The main goal is to print a coupon along with the client order. I'm referencing the Vue.js Shooping Cart by Mike ...

Learn how to effortlessly download a file from Amazon S3 using Angular and ng-click technology

When attempting to download a file from my Amazon S3 bucket using Angular's ng-click, I am receiving a blank file instead of the expected content. HTML <div class="details-field"> RC Book <font class="digit" >({{rcCount}})</font> ...

"Ensure that the jspdf header is configured to display on every page

Currently, I am integrating jspdf code with a jQuery script and the jspdf.debug.js file. My HTML table (angular ng-repeat) is very large and spans multiple pages. While jspdf does a great job repeating the header of the table nicely, I have some invoice in ...

Leveraging various routes to access data with a shared VueJS 3 component

Could you please review this code snippet: It displays two routes that utilize the same component to fetch content from an API. Main.js const router = createRouter({ history: createWebHistory(), routes: [ { path: "/route1& ...

What is the best way to implement a Fibonacci sequence using a for...of loop?

**Can someone show me how to generate Fibonacci numbers using the for...of loop in JavaScript?** I've tested out the following code and it's giving me the desired output: function createFibonacci(number) { var i; var fib = []; // Initi ...

TypeScript compilation error caused by typing issues

My current setup includes typescript 1.7.5, typings 0.6.9, and angular 2.0.0-beta.0. Is there a way to resolve the typescript compile error messages related to the Duplicate identifier issue caused by typings definition files? The error message points ou ...

Ways to maximize the potential of vue-auth features while bypassing the necessity of its login function

As a newbie to VueJS, I am diving into building authorization functions for my website. Initially, I decided to utilize the library called Vue-auth to manage authorization tasks. Surprisingly, it worked seamlessly and below is a snippet of my code: Login. ...

The program successfully executes its function, however, an error message appears stating: "Error: Cannot alter headers after they have already been sent to the client."

During testing the update post feature in my MERN project, I encountered a strange issue. The post would update successfully, but the page would disappear and I would receive the following error message. However, after restarting the server, the updated po ...

How can I trigger my function when the selected index in a radio button list changes in ASP.NET without refreshing the entire page?

In the form, I have a table with multiple rows, each containing a RadioButtonList. When a user selects an item in the RadioButtonList, I need to retrieve the index of the selected item without refreshing the page. ...

Are you looking to combine Jquery's .hover and .hoverIntent functions in your code?

Looking for help with getting two scripts to work together, I am struggling to write the code that will make them function in unison. Specifically, I have a Jquery .hoverIntent placed on the first li element of my mega menu and a Jquery .hover event to dar ...

ForkJoin Observable failing to trigger events

Having an issue with implementing forkJoin on two Observables in my code. Despite directly subscribing to them yielding a response, the forkJoin function doesn't seem to be triggering. Any suggestions on what might be causing this? private data$: Obse ...

Manipulate JSON objects using AngularJS to filter an array based on its unique identifier rather than its index position

Is there a way to filter this JSON data by an element (in this case the id) without relying on the index? ABC: [{ ID: home, elementsHome: [ { el1: x, el2: y}, { el3: d, el4: s}] }, { ID: payments, e ...

Syntax for TypeScript generic promises definition

I'm struggling to fully grasp the definition of Promise in TypeScript, as shown below: /** * Represents the completion of an asynchronous operation */ interface Promise<T> { /** * Attaches callbacks for the resolution and/or rejectio ...

How to schedule FCM notifications at a specific time using Firebase cloud functions

I need help figuring out how to schedule a Firebase Cloud Messaging notification to be sent at a specific time using cloud functions. Currently, the notification is triggered whenever a new document is created in a Firestore database, with the scheduled t ...

Tips for closing the mobile navigation bar on your device after clicking

Currently developing a website and in need of assistance with the mobile device navbar functionality. Essentially, I am looking to close the navigation when a specific link, such as "Destaques", is clicked. All I require is to remove the class "opened" upo ...

Capture any clicks that fall outside of the specified set

I am facing an issue with my navigation drop down menu. Currently, the pure CSS functionality requires users to click the link again to close the sub-menu. What I want is for the sub-menu to close whenever a click occurs outside of it. I attempted a solu ...

Show choices of radio buttons based on the attributes available in the dictionary

I am struggling to dynamically display radio buttons based on the number of roi_ attributes (e.g. roi0 or roi1) for each frame_number. For instance, if frame_number 1 has only one roi_ attribute (roi0), then only one radio button should be displayed. How ...