Skip to content
A set of matchers to assert a spy was called n times
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
LICENSE
README.md
bower.json
jasmine-n-matchers.js
package.json

README.md

jasmine-n-matchers

A set of matchers to assert a spy was called n times

The 2.0.0 release supports Jasmine 2.0. Everything earlier is for Jasmine 1.3.

Usage

Make sure the jasmine-n-matchers.js file is executed early in your tests, it uses beforeEach to register the matchers.

Example

var spy = jasmine.createSpy('spy');

expect(spy).toHaveBeenCalledNTimes(0);

spy('foo', 'bar');

expect(spy).toHaveBeenCalledNTimes(1);
expect(spy).toHaveBeenCalledOnce();
expect(spy).toHaveBeenCalledOnceWith('foo', 'bar');

spy('foo', 'bar');

expect(spy).toHaveBeenCalledNTimes(2);
expect(spy).toHaveBeenCalledTwice();
expect(spy).toHaveBeenCalledTwiceWith('foo', 'bar');

spy('bar', 'baz');

expect(spy).toHaveBeenCalledNTimes(3);
expect(spy).toHaveBeenCalledThrice();
expect(spy).toHaveBeenCalledTwiceWith('foo', 'bar');
expect(spy).toHaveBeenCalledOnceWith('bar', 'baz');

spy('foo', 'bar');
spy('foo', 'bar');

expect(spy).toHaveBeenCalledNTimes(5);
expect(spy).toHaveBeenCalledNTimesWith(4, 'foo', 'bar');
Something went wrong with that request. Please try again.