Coder Social home page Coder Social logo

jasmine_eventually's Introduction

Jasmine Eventually

STATUS: Not maintained


Asynchronous matching without runs and waitsFor.

Usage

describe('jasmineEventually', function() {
  it('allows to match asynchronously with implicit polling', function() {
    var spy = jasmine.createSpy();

    setTimeout(function() {
      spy();
    }, 100);

    expect(spy).eventually.toHaveBeenCalled();
  });
});

is equivalent to

describe('jasmineEventually', function() {
  it('allows to match asynchronously with implicit polling', function() {
    var spy = jasmine.createSpy();

    setTimeout(function() {
      spy();
    }, 100);

    waitsFor(function() {
      return spy.wasCalled;
    });

    runs(function() {
      expect(spy).toHaveBeenCalled();
    });
  });
});

eventually inserts a waitsFor block which silences the matcher output and polls its result until it becomed true.

Here be Dragons

eventually only works for matchers which use the actual object passed to expect as a reference. The following will not work:

describe('jasmineEventually', function() {
  it('can not operate on primitive types', function() {
    var elapsed = false;

    setTimeout(function() {
      elapsed = true;
    }, 100);

    // WILL NOT WORK
    expect(elapsed).eventually.toBeTruthy();
  });
});

elapsed is passed as a value. Setting the variable to true later on does not change the value visibile inside the matcher.

Installation

Just link src/jasmine_eventually.js from your jasmine spec runner and put this setup somewhere inside your support files:

beforeEach(function() {
  jasmineEventually.setup();
});

License

Please fork and improve.

Copyright (c) 2011 Tim Fischbach. This software is licensed under the MIT License.

jasmine_eventually's People

Contributors

tf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

dgrekov

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.