Expect(...)。objectContaining不是Jest中的函数

Tay*_*tin 2 javascript jestjs

我正在使用Jest并尝试比较是否将我的身体格式化为对象的结构{cart_id: 'string', payment: 'string', site: 'string'},但是当我执行以下操作时:

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

我收到上面的错误。我查看了文档,但不确定是否要像他们的示例中的示例一样进行toBeCalled处理:https ://facebook.github.io/jest/docs/en/expect.html#expectobject containsobject

Tay*_*tin 7

我只需要添加一个“比较”功能:

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

只是不停地弄乱它,并使它起作用。