Skip to content

Releases: chaijs/chai-spies

v1.1.0

31 Oct 12:10
a0b206c
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 1.0.0...v1.1.0

1.0.0 / 2018-01-10

12 Jan 10:33
ededa6a
Compare
Choose a tag to compare

This is a major release which introduces many new featues, such as sandboxes, as well as new convenience methods and assertions.

This major release also comes with some breaking changes:

Breaking Changes

  • removed reset method. #35 (@stalniy)
    You will need to update any callsites to spy.reset() to instead assign a new spy to that variable or property.

  • exposes original function body in spy.toString calls #93 (@stalniy)
    If you check the spy.toString() output in your tests, this will need to be changed to accomodate for this change.

Features

chai.spy.on(array, 'push', returns => 5)
chai.spy.on(array, 'push', function() {
  // custom implementation
})
  • added spy.restore #61 (#38, @stalniy)
    Allows to remove spies added by spy.on and restore original method implementation

  • added support for sanboxes #61 (#38, @stalniy)
    Now it's possible to create sanboxes and track/restore spies in sandbox

  • added support for nth call checks #75 (#59, @cnexans)
    Allows to check spy arguments on specified call

const spy = chai.spy()

spy(1); // first call
spy(2); // second call
spy(3); // third call
spy(i); // nth call

expect(spy).to.have.been.first.called.with(1)
expect(spy).to.have.been.second.called.with(2)
expect(spy).to.have.been.third.called.with(3)
expect(spy).on.nth(i).be.called.with(i)

Bug Fixes

Documentation

0.7.1 / 2015-09-21

21 Sep 20:54
Compare
Choose a tag to compare

Added chai-spies to the bower registry!

Community Contributions

  • #36 Add bower.json to chai-spies package
    By @rcchen

0.7.0 / 2015-07-24

24 Jul 22:18
Compare
Choose a tag to compare

Added .spy.reset() method, to reset call counters back to 0

var spy = chai.spy('foo');
spy();
spy.should.have.been.called();
spy.reset();
spy.should.not.have.been.called();

Community Contributions

Code Features & Fixes

0.6.0 / 2015-04-24

26 Apr 15:45
Compare
Choose a tag to compare

Added .spy.on and .spy.object to easily make new spies, for example:

// Returns `fs` but with readFile and readFileSync spied on
var fs = chai.spy.object(fs, ['readFile', 'readFileSync']);

// Shortcut for `fs.writeFile = chai.spy(fs.writeFile)`
chai.spy.on(fs, 'writeFile');

Added new assertions:

  • .called.min(n)/.at.least(n) to assert a spy has been called a minimum of
    n many times.
  • .called.max(n)/.at.most(n) to assert that a spy has been called at most n
    number of times.

Community Contributions

Code Features & Fixes

Documentation fixes

0.5.1 / 2012-11-15

25 Apr 11:16
Compare
Choose a tag to compare

Small bugfix, fixing the output of the .called(n) assertion error.

0.5.0 / 2012-11-14

25 Apr 11:16
Compare
Choose a tag to compare

A few new features:

  • Add .with() and .exactly.with() assertion for asserting what arguments
    a spy was called with.

0.4.0 / 2012-10-09

25 Apr 11:16
Compare
Choose a tag to compare

Ensure spies return the value of their wrapped functions

Community Contributions

Code Features & Fixes

0.3.0 / 2012-07-11

25 Apr 11:15
Compare
Choose a tag to compare

Add ability for spies to have an (optional) name.

Community Contributions

Code Features & Fixes

Documentation fixes

0.2.3 / 2012-07-09

25 Apr 11:15
Compare
Choose a tag to compare

Small bugfixes, improving the AMD wraper