1.0.0 / 2018-01-10
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 tospy.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 thespy.toString()
output in your tests, this will need to be changed to accomodate for this change.
Features
-
added spy.returns #35 (@stalniy)
Allows to create spies that return constant value -
added spy.on #61 (#38, @stalniy)
Allows to add spies on existing methods -
added posibility to replace original method when spying with
spy.on
#68 (#62, @stalniy)
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 byspy.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
- removed dead links in README #84, #80 (#79, @damianb)
- fixed formatting in README #67 (@jethrolarson)
- added MIT license to package.json #58 (@reiz)
- fixed
.with
when multiple identical arguments are passed in spy call #56 (#45, @meeber) - updated reference to github repository #42 (@robcolburn)