tests: add tryAssertion command to replace cy.wait

This commit is contained in:
braks
2022-10-13 23:23:43 +02:00
committed by Braks
parent 0613350554
commit 5aa94e2e13
11 changed files with 78 additions and 42 deletions
+21
View File
@@ -49,6 +49,24 @@ const useViewPort = () => cy.get('.vue-flow__viewport')
const useTransformationPane = () => cy.get('.vue-flow__transformationpane')
const retry = (assertion: Function, { interval = 20, timeout = 1000 } = {}) => {
return new Promise((resolve, reject) => {
const startTime = Date.now()
const tryAgain = () => {
setTimeout(() => {
try {
resolve(assertion())
} catch (err) {
Date.now() - startTime > timeout ? reject(err) : tryAgain()
}
}, interval)
}
tryAgain()
})
}
// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
@@ -60,6 +78,7 @@ declare global {
vueFlow: typeof mountVueFlow
viewPort: typeof useViewPort
transformationPane: typeof useTransformationPane
tryAssertion: typeof retry
}
}
}
@@ -72,5 +91,7 @@ Cypress.Commands.add('viewPort', useViewPort)
Cypress.Commands.add('transformationPane', useTransformationPane)
Cypress.Commands.add('tryAssertion', retry)
// Example use:
// cy.mount(MyComponent)