Giter Site home page Giter Site logo

jasmine-intercept's Introduction

DEPRECATION NOTICE [7 JAN 2014]

jasmine-intercept has been superseded by where.js

Build Status

jasmine-intercept

Provides an intercept() method for the Jasmine BDD test framework, in order to capture expected failures and report them as passed to the jasmine reporter, mainly as a shield for continuous integration environments.

Thanks to:

  • Jamon Holmgren (@jamonholmgren) for your feedback regarding this API.

justify

tl;dr ~ needed this while using jasmine to test-drive my jasmine-where repo.

Read more about that here.

npm

npm install jasmine-intercept

git clone https://github.com/dfkaye/jasmine-intercept.git

important

Including or requiring jasmine-intercept adds an intercept() method to the global environment, for example:

require('jasmine-intercept');

intercept === global.intercept === jasmine.getEnv().intercept;

<script -- jasmine 1 or 2 scripts first -->
<script src="../jasmine-intercept.js"></script>

intercept === window.intercept === jasmine.getEnv().intercept;

use

intercept takes a function with a body of expectations and returns a results object containing arrays of failing and passing messages generated by the spec runner.

Use var messages = intercept(function () { // body of spec }) to capture expected failures in order to prevent them appearing as failed in the jasmine reporter.

Inspect the returned messages.failing and messages.passing arrays for length and content.

examples

Use in an it-eration:

it('should intercept messages', function () {
      
  var messages = intercept(function() {
    expect(1).toBe(1);
    expect(typeof drink).toBe('mixed'); // should be 'undefined'
  });
  
  expect(messages.failing.length).toBe(1);
  expect(messages.failing[0]).toBe("Expected 'undefined' to be 'mixed'.");
  expect(messages.passing.length).toBe(1);
});

Use in asynchronous it-eration:

it('should intercept asynchronous messages', function (done) { // <= pass done here

  setTimeout(function () {
  
    var messages = intercept(function() {
      expect(1).toBe(1);
      expect(typeof drink).toBe('mixed'); // should be 'undefined'
    });
    
    expect(messages.failing.length).toBe(1);
    expect(messages.failing[0]).toBe("Expected 'undefined' to be 'mixed'.");
    expect(messages.passing.length).toBe(1);
    
    done(); // <= call done here
    
  }, 500);
  
});

jasmine versions supported

Current implementation runs in both jasmine 1.3.1 and jasmine 2.0.0-rc3.

Using jasmine-node which uses jasmine 1.3.1 internally.

jasmine-node --verbose ./test/suite.spec.js

or simply

npm test

rawgit test page

The jasmine2 browser test page is viewable on rawgit.

testem

Using testemjs to drive tests in multiple browsers for jasmine-2.0.0 (see how to hack testem for jasmine 2), as well as jasmine-node. The following command uses a custom launcher for jasmine-node in testem:

testem -l j

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.