最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - expect(...).objectContaining is not a function in Jest - Stack Overflow

programmeradmin0浏览0评论

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: .html#expectobjectcontainingobject

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

Share Improve this question edited Jun 21, 2018 at 5:23 Joshua 3,1763 gold badges26 silver badges40 bronze badges asked Jun 20, 2018 at 14:32 Taylor AustinTaylor Austin 5,98716 gold badges63 silver badges108 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 22

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.

发布评论

评论列表(0)

  1. 暂无评论