Skip to content

Commit b37820a

Browse files
committed
Fix poor test of resetHistory
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.
1 parent a8171c3 commit b37820a

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

test/collection-test.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -458,29 +458,40 @@ describe("collection", function () {
458458
describe(".resetHistory", function () {
459459
beforeEach(function () {
460460
this.collection = Object.create(sinonCollection);
461-
this.collection.fakes = [{
462-
// this fake has a resetHistory method
463-
resetHistory: sinonSpy()
464-
}, {
465-
// this fake has a resetHistory method
466-
resetHistory: sinonSpy()
467-
}, {
468-
// this fake pretends to be a spy, which does not have resetHistory method
469-
// but has a reset method
470-
reset: sinonSpy()
471-
}];
461+
var spy1 = sinonSpy();
462+
spy1();
463+
464+
var spy2 = sinonSpy();
465+
spy2();
466+
467+
this.collection.fakes = [
468+
spy1,
469+
spy2
470+
];
472471
});
473472

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

479477
this.collection.resetHistory();
480478

481-
assert(fake0.resetHistory.called);
482-
assert(fake1.resetHistory.called);
483-
assert(fake2.reset.called);
479+
refute(fake0.called);
480+
refute(fake1.called);
481+
});
482+
483+
it("calls reset on fake that do not have a resetHistory", function () {
484+
var noop = function noop() {};
485+
486+
noop.reset = function reset() {
487+
noop.reset.called = true;
488+
};
489+
490+
this.collection.fakes.push(noop);
491+
492+
this.collection.resetHistory();
493+
494+
assert.isTrue(noop.reset.called);
484495
});
485496
});
486497

0 commit comments

Comments
 (0)