Giter Club home page Giter Club logo

trytryagain's Introduction

If at first you don't succeed, try try again

if at first you don't succeed, try try again

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.

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 install trytryagain

retry

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.

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.

trytryagain's People

Contributors

refractalize avatar

Watchers

Derek Ekins avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.