Skip to content

1.0.0 / 2018-01-10

Compare
Choose a tag to compare
@keithamus keithamus released this 12 Jan 10:33
ededa6a

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