Jest doesn't recognize the function expect(...).objectContaining

Currently, I am utilizing Jest to test the structure of an object with attributes

{cart_id: 'string', payment: 'string', site: 'string'}
. However, when I attempt the following:

 test('paymentRequest should be formatted', () => {
    expect(paymentRequest(paymentBody)).objectContaining({
      cart_id: expect.any(String),
      payment: expect.any(String),
      site: expect.any(String)
    })
  })

An error is being thrown. I have checked the documentation but am unsure about the usage of toBeCalled with, as shown in their example here: https://facebook.github.io/jest/docs/en/expect.html#expectobjectcontainingobject

Answer №1

I finally found the solution by adding a "compare" function:

 test('paymentRequest should be formatted', () => {
    expect(paymentRequest(paymentBody)).toEqual(
      expect.objectContaining({
        cart_id: expect.any(String),
        payment: expect.any(String),
        site: expect.any(String)
      })
    )
  })

After some trial and error, I managed to make it work.

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

The issue of race condition in Node.js programming

I've been diving into the documentation, but I'm struggling to figure out what's going on here. I have two functions: one downloads a CSV file via a URL, and the next function takes that CSV file and converts it to JSON FileDownload.js co ...

Having trouble sending data from the controller to the view in Laravel 8

I am struggling to display data retrieved from the database in my view through the controller. Despite trying various solutions found on similar questions, none of them seem to be effective. My main goal is to showcase a list of employees on my admin page. ...

Struggling with generating forms using AJAX, Javascript, and HTML depending on the selection made from a drop-down menu

I am in need of a simple web form for work submissions within my organization. These submissions will fit into 4 Categories, each requiring unique information. Currently, I have a basic form set up with fields such as Requested Name, Requested Date, Acquis ...

Having trouble with the find method when trying to use it with the transform

In my code, I have three div elements with different values of the transform property assigned to them. I store these elements in a variable using the getElementsByClassName method and then try to find the element where the value of the transform property ...

Strange response received from $http GET request on Android device running Crosswalk

I am attempting to retrieve data in JSON format from an API using AngularJS. The process is successful on iOS and desktop browsers, but I'm encountering a strange response when trying it on my Android device. The request code looks like this: $http({ ...

Tips for determining the zoom factor through mouse scrolling using jQuery

Is there a way to zoom in on a page when the user scrolls using ctrl + ,? If I determine the Zoom factor, can I then zoom in on the current page based on that factor? For example, if the zoom factor is 1.44, can I convert this to 144% and carry out the ...

Accessing website login - <div> and validating user entry

I am currently working on developing a basic login webpage, but I am facing issues with the rendering of the page. Below is the code I am using: function logIn(username, password){ var username = document.getElementById("username").value; var p ...

What is Angular's approach to handling elements that have more than one directive?

When an element in Angular has multiple directives, each specifying a different scope definition such as scope:false, scope:true, or scope:{}, how does the framework handle this complexity? ...

Validate the button's status in Ionic

When I click on a button, I am trying to retrieve the Toggle state immediately. However, I consistently receive a value of true, even when my toggle is actually set to false. I believe the issue lies in how I am manipulating the DOM. Here is an example ...

How can I trigger the offcanvas opening in Bootstrap 5 through code?

I am having an issue with a bottom offcanvas on my webpage. I want to open it when a card is clicked, but despite trying to set the necessary attributes and using code from the documentation, it only shows the backdrop briefly before immediately dismissing ...

Restricting variable values in Node.js

As I work in an IDE, there is a feature that helps me with autocomplete when typing code. For example, if I type: x = 5 s = typeof(x) if (s === ) //Cursor selection after === (before i finished the statement) The IDE provides me with a list of possible ...

Trouble with Updating InnerHTML

xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", "myurlhere.php", true ); xmlHttp.send(); var display = document.getElementById("display"); display.innerHTML = xmlHttp.response; This snippet of code is part of a function triggered by a button click. ...

What is the best way to showcase the information stored in Firestore documents on HTML elements?

Currently in the process of designing a website to extract data from my firestore collection and exhibit each document alongside its corresponding fields. Below is the code snippet: <html> <!DOCTYPE html> <html lang="en"> <head> ...

Guide on implementing EdgesHelper with imported Collada model using three.js

Having some issues while using the EdgesHelper on a loaded Collada model in three.js: Applying edges to the entire model geometry, Misalignment and scale discrepancies between the Collada model and the generated edges. View Demo var controls, scene, ca ...

Ways to utilize/extract data from an enumeration

Hello there! I am currently diving into the world of React and Typescript, eager to expand my knowledge. Please bear with me if my explanations are not up to par. In my react app, I have a scenario where I created an enum that I want to utilize in two diff ...

Understanding the rotation direction or handedness in three.js

It has come to my attention that when I perform rotation around the Z axis on my model, as shown below: model.rotateZ(rotatedAngle * Math.PI / 180); The rotation appears to be in a counter-clockwise direction around the axis. Can this observation be co ...

Is it secure to store the access token within the NextAuth session?

Utilizing a custom API built with Node.js and Express.js, I have implemented nextAuth to authenticate users in my Next.js application. Upon a successful login, the date is stored in the nextAuth session and can be accessed using the useSession hook. To acc ...

Customize Bootstrap radio buttons to resemble standard buttons with added form validation styling

Is there a way to style radio buttons to look like normal buttons while maintaining their functionality and form validation? I have two radio buttons that need styling but should still behave like radio buttons. Additionally, I am utilizing Bootstrap for s ...

React App folders are not being properly installed through NPX

Encountering an error message while attempting to use npx create-react-app Husna@LAPTOP-LPCC954R MINGW64 ~/Desktop/React GitHib Project (master) $ npx create-react-app github2020 Creating a new React app in C:\Users\Husna\Desktop\Reac ...

Which element from the context menu has been selected?

We specialize in creating browser extensions for Chrome, Firefox, and Safari. Our latest project involves implementing context menus within the extensions that will appear when users right-click on any editable form element. I attempted to incorporate an e ...