was called times

  • <spy> was called times <number>

Passes if the spy was called exactly the specified number of times.

var increment = sinon.spy();
increment(41);
increment(42);
increment(43);
expect(increment, 'was called times', 3);

In case of a failing expectation you get the following output:

var add = sinon.spy().named('add');
add(41, 42);
add(41, 43);
add(41, 44);
add(41, 45);
expect(add, 'was called times', 2);
expected add was called times 2
  
expected
add( 4142 ); at theFunction (theFileName:xx:yy)
add( 4143 ); at theFunction (theFileName:xx:yy)
add( 4144 ); at theFunction (theFileName:xx:yy)
add( 4145 ); at theFunction (theFileName:xx:yy)
to have length 2
  
expected 4 to be 2

You have the following convinient aliases available:

var spy = sinon.spy();
spy(1);
expect(spy, 'was called once');
spy(2);
expect(spy, 'was called twice');
spy(3);
expect(spy, 'was called thrice');