Skip to content

Commit

Permalink
Fix poor test of resetHistory
Browse files Browse the repository at this point in the history
The test implementation was using objects with `resetHistory` methods.
However, the only valid things to have in the `fakes` collection are
spies (functions) or property descriptors (objects with spies), which
have `resetHistory` methods.
  • Loading branch information
mroderick committed Jan 26, 2018
1 parent a8171c3 commit b37820a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions test/collection-test.js
Expand Up @@ -458,29 +458,40 @@ describe("collection", function () {
describe(".resetHistory", function () {
beforeEach(function () {
this.collection = Object.create(sinonCollection);
this.collection.fakes = [{
// this fake has a resetHistory method
resetHistory: sinonSpy()
}, {
// this fake has a resetHistory method
resetHistory: sinonSpy()
}, {
// this fake pretends to be a spy, which does not have resetHistory method
// but has a reset method
reset: sinonSpy()
}];
var spy1 = sinonSpy();
spy1();

var spy2 = sinonSpy();
spy2();

this.collection.fakes = [
spy1,
spy2
];
});

it("resets the history on all fakes", function () {
var fake0 = this.collection.fakes[0];
var fake1 = this.collection.fakes[1];
var fake2 = this.collection.fakes[2];

this.collection.resetHistory();

assert(fake0.resetHistory.called);
assert(fake1.resetHistory.called);
assert(fake2.reset.called);
refute(fake0.called);
refute(fake1.called);
});

it("calls reset on fake that do not have a resetHistory", function () {
var noop = function noop() {};

noop.reset = function reset() {
noop.reset.called = true;
};

this.collection.fakes.push(noop);

this.collection.resetHistory();

assert.isTrue(noop.reset.called);
});
});

Expand Down

0 comments on commit b37820a

Please sign in to comment.