我正在使用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)
})
})
我收到上面的错误。我查看了文档,但不确定是什么与BeBeCalled所做的一样,例如此处的示例:https://facebook.github.io/jest/docs/en/expect.html#expectobjectcontainingobject
答案 0 :(得分:4)
我只需要添加一个“比较”功能:
test('paymentRequest should be formatted', () => {
expect(paymentRequest(paymentBody)).toEqual(
expect.objectContaining({
cart_id: expect.any(String),
payment: expect.any(String),
site: expect.any(String)
})
)
})
只是不断弄乱它,并使它起作用。