[英]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: 我正在使用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)
})
})
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
我看了一下这些文档,并不确定BeCalled与他们在这里的示例有什么关系: 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. 只是不停地搞乱它并让它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.