Skip to content
Add the Cypress waiting power to virtually everything πŸŽ‰
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cypress refactor: πŸ’‘ Move ts defintion on root Apr 27, 2019
public feat: 🎸 Implement timeout. Add test Apr 27, 2019
src feat: 🎸 `checkFunction` should be a function Apr 27, 2019
.all-contributorsrc docs: update .all-contributorsrc Apr 27, 2019
.gitignore Fix option name Apr 27, 2019
.travis.yml chore: πŸ€– Add a basic front-end app Apr 27, 2019
README.md
cypress.json feat: 🎸 Avoid to record video on test Apr 27, 2019
index.d.ts refactor: πŸ’‘ Move ts defintion on root Apr 27, 2019
package.json
tsconfig.json refactor: πŸ’‘ Move ts defintion on root Apr 27, 2019
yarn.lock feat: 🎸 Typescript definition Apr 27, 2019

README.md

cypress-wait-until

Add the Cypress waiting power to virtually everything πŸŽ‰

Commitizen friendly Build Status Open Source Love TypeScript Open Source Saturday

Use this plugin to wait for everything not expected by Cypress wait.

Installation

npm i -D cypress-wait-until
# or
yarn add -D cypress-wait-until

Usage

cypress-wait-until extends Cypress' cy command.

Add this line to your project's cypress/support/commands.js:

import 'cypress-wait-until';

Then, in your test, you can write

// wait until a cookie is set
cy.waitUntil(() => cy.getCookie('token').then(cookie => Boolean(cookie && cookie.value)));

// wait until a global variable has an expected value
cy.waitUntil(() => cy.window().then(win => win.foo === "bar"));

// sync function works too!
cy.waitUntil(() => true);

// with all the available options
cy.waitUntil(() => cy.window().then(win => win.foo === "bar"), {
  timeout: 2000, // waits up to 2000 ms, default to 5000
  interval: 500 // performs the check every 500 ms, default to 200
});

If you return a truthy value, it becomes the subject for the next command. So you can assert about it too

// wait until the Recaptcha token will be added to the dedicated hidden input field...
cy.waitUntil(() => cy.get("input[type=hidden]#recaptchatoken").then($el => $el.val()))
  // ... then, check that it's valid string asserting about it
  .then(token => expect(token).to.be.a("string").to.have.length.within(1, 1000));

Arguments

  • checkFunction

A function that must return a truthy value when the wait is over.

  • options:Object (optional)

Pass in an options object to change the default behavior of cy.waitUntil().

Option Default Description
timeout 5000 Time to wait for the checkFunction to return a truthy value before throwing an error.
interval 200 Time to wait between the checkFunction invocations.


Why did we write it?

A lot of StackOverflow users had some difficulties in implementing a recursive promise with Cypress just to repeatedly check for something to happen (see two of the various questions about the topic: How can i wait for each element in a list to update to a certain text? And How do I wait until a cookie is set?).
This plugin is dedicated to them ❀️

Open Source Saturday

This project has been made during one of the Open Source Saturdays, a series of Milan-based events where everyone codes just to spread some Open Source love ❀️

Contributors

Thanks goes to these wonderful people (emoji key):

Stefano Magni
Stefano Magni

πŸ’» ⚠️ πŸ“–
Tommaso Allevi
Tommaso Allevi

πŸ’» ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

You can’t perform that action at this time.