admin管理员组

文章数量:1279122

My issue is that I'd like to have a timeout on the expect assertion from Cypress's library but can't seem to figure out a method to do so.

I've tried greatly increasing the global timeout in cypress.conf; however, that didn't work.

if ($widget.find('report-widget')) {
  SVGCount++;
  expect(barGraphsChange[index]).to.not.equal(undefined)
  console.log(barGraphsChange, index)
  cy.getBarGraphTotal(SVGCount, barGraphsChange[index])
}

If not a timeout then a reasonable workaround would be nice as well, Thanks!

Also a note: barGraphsChange[index] is in the process of getting calculated and assigned from a called custom Cypress mand earlier on during this phase.

My issue is that I'd like to have a timeout on the expect assertion from Cypress's library but can't seem to figure out a method to do so.

I've tried greatly increasing the global timeout in cypress.conf; however, that didn't work.

if ($widget.find('report-widget')) {
  SVGCount++;
  expect(barGraphsChange[index]).to.not.equal(undefined)
  console.log(barGraphsChange, index)
  cy.getBarGraphTotal(SVGCount, barGraphsChange[index])
}

If not a timeout then a reasonable workaround would be nice as well, Thanks!

Also a note: barGraphsChange[index] is in the process of getting calculated and assigned from a called custom Cypress mand earlier on during this phase.

Share Improve this question asked Aug 12, 2019 at 16:20 Ahm23Ahm23 3661 gold badge3 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You can customise your expectations with should(), and this will automatically retry your assertions for either the specified timeout, or the global defaultCommandTimeout if none provided. In your case I could probably imagine wrapping your object, specify a timeout and then passing your logic to should:

cy.wrap(someFunction, {timeout: 25000}).should(someFunction => expect(someFunction()).to.eq(someValue))

Read more here: https://docs.cypress.io/api/mands/should.html#Function

本文标签: javascriptSet timeout for Cypress expect assertionStack Overflow