npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

testdouble-jasmine

v0.2.1

Published

Jasmine matcher for use with testdouble.js's verify() function

Downloads

248

Readme

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.