如何使用赛普拉斯检查对象数组中的值是否等于某个值?
How to check if the value from array of object is equal to certain value using cypress?
嗨,我有一个像这样的对象数组,
const arr_obj = [
{
value: '100',
id: '1',
}
]
cypress test code is like below,
it('some test' , () => {
const expectedValue = 200;
cy.apiGetObject(id).then((arr_obj) => {
expect(arr_obj[0].value).should('eq', expectedValue);
}
});
我必须尝试检查 arr_obj[0].value 是否等于上面的 expectedValue。但它给出了错误
无效的 chai 属性 应该
如果 arr_obj[0].value 和 expectedValue 相同,我应该如何检查 cypress。
有人可以帮我解决这个问题吗?谢谢。
expect
和 should
是两种不同类型的断言,不能一起使用。
所以如果你想使用 expect
你必须使用:
expect(arr_obj[0].value).to.equal(expectedValue)
如果您想使用 should
,您可以这样做:
cy.wrap(arr_obj[0].value).should('eq', expectedValue)
嗨,我有一个像这样的对象数组,
const arr_obj = [
{
value: '100',
id: '1',
}
]
cypress test code is like below,
it('some test' , () => {
const expectedValue = 200;
cy.apiGetObject(id).then((arr_obj) => {
expect(arr_obj[0].value).should('eq', expectedValue);
}
});
我必须尝试检查 arr_obj[0].value 是否等于上面的 expectedValue。但它给出了错误
无效的 chai 属性 应该
如果 arr_obj[0].value 和 expectedValue 相同,我应该如何检查 cypress。
有人可以帮我解决这个问题吗?谢谢。
expect
和 should
是两种不同类型的断言,不能一起使用。
所以如果你想使用 expect
你必须使用:
expect(arr_obj[0].value).to.equal(expectedValue)
如果您想使用 should
,您可以这样做:
cy.wrap(arr_obj[0].value).should('eq', expectedValue)