https://github.com/featurist/trytryagain
Keep retrying until it works. Actually a very reliable testing strategy.
https://github.com/featurist/trytryagain
Last synced: about 2 months ago
JSON representation
Keep retrying until it works. Actually a very reliable testing strategy.
- Host: GitHub
- URL: https://github.com/featurist/trytryagain
- Owner: featurist
- Created: 2014-08-12T16:36:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-31T19:54:47.000Z (about 9 years ago)
- Last Synced: 2025-03-04T02:51:17.830Z (about 2 months ago)
- Language: PogoScript
- Size: 9.77 KB
- Stars: 4
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# If at first you don't succeed, try try again
[](http://www.youtube.com/watch?v=WwlWgMTCp8w)
Retrying assertions is a very reliable strategy for testing applications, whether you're testing in the browser, on mobile, or testing networked applications. Anywhere timing is variable.
```JavaScript
var retry = require('trytryagain');describe('my application', function () {
it('has the right title', function () {return retry(function () {
return browser.title().then(function (title) {
return expect(title).to.equal('My App');
});});
});
});
```## NPM: [trytryagain](https://www.npmjs.org/package/trytryagain)
```sh
npm install trytryagain
```## retry
```JavaScript
var promise = retry(function, [options]);
var promise = retry([options], function);
```* `function` is a function that will be called repeatedly until it doesn't throw an exception, or return a promise that is rejected.
* `options.timeout` millisecond to retry until giving up. default 1000.
* `options.interval` retry interval in milliseconds. default 10.Returns a promise. If the function eventually returns a value then this promise will be fulfilled with that value. If the function continually throws or rejects, then this function will be rejected with the error.
## retry.ensuring
`retry.ensuring` is kind of the oppposite of `retry`, it keeps trying the assertion as long as it doesn't fail, and fails immediately if it fails. This is useful in situation where you want to ensure that something **doesn't** happen, but you want to check long enough to be sure.
```js
var promise = retry.ensuring(function, [options]);
var promise = retry.ensuring([options], function);
```* `function` is a function that will be called repeatedly until it does throw an exception, or until `duration` milliseconds has passed.
* `options.duration` milliseconds to retry before declaring success. default 1000.
* `options.interval` retry interval in milliseconds. default 10.