Skip to content

Commit

Permalink
fix: Update async example for Cy 12 changes around .invoke()
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWinds committed Nov 9, 2022
1 parent fb50ad5 commit 5b40288
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

Cypress.Commands.add('asyncAdd', (a, b) => {
cy.log(`${a} + ${b}`)
// our application in "index.html" has placed a promise-returning

// After 1000 ms, our application's index.html adds a promise-returning
// method "asyncAdd" onto the "window" object.
// from the tests's custom command we can invoke that method
// Cypress automatically waits for the promises to resolve
// before yielding their value to the next command in the test
// https://on.cypress.io/invoke
cy.window().invoke('asyncAdd', a, b)
// .its() waits for this to exist before passing it to .then().

// .then() in turn automatically waits for the returned promise to resolve
// before yielding its value to the next command in the test
// https://on.cypress.io/then
cy.window().its('asyncAdd').then(add => add(a, b))
})

describe('example', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

Cypress.Commands.add('asyncAdd', (a, b) => {
cy.log(`${a} + ${b}`)
// our application in "index.html" has placed a promise-returning

// After 1000 ms, our application's index.html adds a promise-returning
// method "asyncAdd" onto the "window" object.
// from the tests's custom command we can invoke that method
// Cypress automatically waits for the promises to resolve
// before yielding their value to the next command in the test
// https://on.cypress.io/invoke
cy.window().invoke('asyncAdd', a, b)
// .its() waits for this to exist before passing it to .then().

// .then() in turn automatically waits for the returned promise to resolve
// before yielding its value to the next command in the test
// https://on.cypress.io/then
cy.window().its('asyncAdd').then((add) => add(a, b))
})

describe('example', () => {
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b40288

Please sign in to comment.