简体   繁体   中英

expect(…).objectContaining is not a function in Jest

I am using Jest and trying to compare if my body is being formatted into the structure of an object with {cart_id: 'string', payment: 'string', site: 'string'} , but when I do something like this:

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

I get the error above. I looked at the documentation and not really sure what toBeCalled with does like they have in their example here: https://facebook.github.io/jest/docs/en/expect.html#expectobjectcontainingobject

I just need to add 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)
      })
    )
  })

Just kept messing around with it and got this to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM