GitXplorerGitXplorer
B

testdouble-jasmine

public
3 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
c50b87610c47ed38261da1e572b5e6301bc948fc

0.2.1

BBrianGenisio committed 9 years ago
Unverified
3456bade6f5c1c3157d35918bb4ed4fae5d12132

provide an alternate calling mechanism to add testdouble parameters to the verification

BBrianGenisio committed 9 years ago
Unverified
2a6d148ce94954f472324073aa803bbb96604ad1

0.2.0

BBrianGenisio committed 9 years ago
Unverified
3d20ea24dc6884c7cedf6da276caf4034969b8bd

Allow parameters to be passed into 2.0 matchers

BBrianGenisio committed 9 years ago
Unverified
c12c35302c3e7a0391a0094ce8b763a4541b386d

0.1.4

BBrianGenisio committed 9 years ago
Unverified
6ccb8122db2b681ec0a0e1e6818163daf0a1729a

Update the matcher-wrapper

BBrianGenisio committed 9 years ago

README

The README file for this repository.

testdouble-jasmine

This is a tiny library (modeled after testdouble-chai) that adds a .toVerify matcher to Jasmine for use with testdouble.js. This matcher can be used as syntactic sugar over the testdouble.verify function. It solves the problem that Jasmine doesn't register testdouble.verify as a legitimate assertion. Jasmine will complain, in fact, if you only include testdouble.verify without another assertion, and will leave it out of the assertion count. This libary fixes that.

Here are some examples:

Use

it("can verify that a testdouble object was called", function() {
	var td = testdouble.function();
	td();
	expect().toVerify(td());
});

or with arguments:

it("can tell you if a testdouble object was called a certain way", function() {
  var td = testdouble.function();
  td("hi");
  expect().toVerify(td("hi"));  // instead of `verify(td("hi"))`!
});

You can pass testdouble options into the verify function if you'd like:

it("can verify the number of times a double is called", function() {
  var td = testdouble.function();
  td();
  td();

  expect().toVerify({called: td(), times: 2});
});

Or, an alternate calling mechanism if you are using Jasmine 2.x:

it("can verify the number of times a double is called", function() {
  var td = testdouble.function();
  td();
  td();

  expect().toVerify(td(), {times: 2});
});

Setup

After installing the library with npm install --save-dev testdouble-jasmine, here's how to get jasmine to know about testdouble-jasmine:

Global

If you want to hook up the matchers for everyone, you can use() this to the top of your spec helper. It will determine whether you are using jasmine 1.x or 2.x and act accordingly:

// at the top of a spec helper
var td = require('testdouble');
var tdJasmine = require('testdouble-jasmine'); 
tdJasmine.use(td); // make sure to call tdJasmine.use with td to register the matcher

More Control

You may not want to add the testdouble matcher to every test. In that case, you can get() the matchers and register them yourself:

Jasmine 1.x

var td = require('testdouble');
var tdMatchers = require('testdouble-jasmine').get(td);

describe('something', function() {
    beforeEach(function() {
        this.addMatchers(tdMatchers);
    });
});

Jasmine 2.x

var td = require('testdouble');
var tdMatchers = require('testdouble-jasmine').get(td);

describe('something', function() {
    beforeEach(function() {
        jasmine.addMatchers(tdMatchers);
    });
});

And you should be good to go! Check out test/testdouble-jasmine_spec.js for an exhaustive description of how this library behaves.