node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »



A little something to help your asserts chill out

Sometimes end-to-end tests talk to external processes and/or servers. Sometimes those external things take a little while to do their stuff. Sometimes you need to assert that stuff happens, eventually.


npm install patience


When you want to make sure something happens within a short time period, call soon(assert, context, callback). This will repeatedly check the assert until it passes, or gives up trying.


Here's something that hopefully gets the idea across. Say I have an assert that looks like this:


That's great if the users list is updated synchronously. But say I'm testing my code in a child process, and using to send users back to a zombie browser when they log in? The test will only pass if the assert happens to run after all that communication has finished.

Instead, I can give it a short while to happen:

soon(function () {
}, this, callback);

This makes my test pass reliably, and as quickly as possible.

Or if I need to check that an async function eventually succeeds (i.e. calls the callback without passing it an error):

soon(function (cb) {
  this.browser.get('', cb);
}, this, callback);