【问题标题】:How to check if the value from array of object is equal to certain value using cypress?如何使用赛普拉斯检查对象数组中的值是否等于某个值?
【发布时间】:2021-10-28 11:47:07
【问题描述】:

嗨,我有一个这样的对象数组,

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 是否等于预期值,如上所示。但它给出了错误

无效的 chai 属性应该

如果 arr_obj[0].value 和 expectedValue 相同,我应该如何检查 cypress。

有人可以帮我解决这个问题吗?谢谢。

【问题讨论】:

    标签: cypress


    【解决方案1】:

    expectshould 是两种不同类型的断言,不能一起使用。

    所以如果你想使用expect,你必须使用:

    expect(arr_obj[0].value).to.equal(expectedValue)
    

    如果你想使用should,你可以这样做:

    cy.wrap(arr_obj[0].value).should('eq', expectedValue)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多