me

mocha-eventually

Retries a test until it eventually works.

Showing:

Popularity

Downloads/wk

14

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

2

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

mocha-eventually

Retries a test until it eventually works.

Status

eventually(callback(next()), [timeout], [interval]) -> Promise

callback is a function. If it's async, it should either consume the next() parameter, or return a promise.

If it doesn't work within timeout milliseconds, it's considered a failure.

If a test fails and timeout has not elapsed yet, it will wait interval milliseconds and try again.

Returns a promise, which Mocha will happily consume.

Examples

var eventually = require('mocha-eventually')

it('eventually works', function () {
  return eventually(function () {
    assert(Math.random() > 0.9)
  }, 2000)
})

Async via callback example

var eventually = require('mocha-eventually')
var myAsyncAction // function that accepts callback

it('eventually works for asynchronous action', function () {
  return eventually(function (next) {
    myAsyncAction(function(err, result) {
      assert(err === null)
      next()
    })
  }, 2000)
})
var eventually = require('mocha-eventually')
var myPromised // function that returns promise

it('eventually works for asynchronous action', function () {
  return eventually(function () {
    return myAsyncAction("someparam")
  }, 2000)
})

Browser support

This extension only works in Node.js environment and can not be used when running Mocha in a browser.


Thanks

mocha-eventually © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial