Sinon issue 2065

node v10.24.1
version: 1.0.0
endpointsharetweet
// Employs 'mini-mocha' to emulate running in the Mocha test runner (mochajs.org) require("@fatso83/mini-mocha").install(); const sinon = require("sinon"); const {assert, refute} = require('@sinonjs/referee'); describe("#2065 - sandbox restore functionality", function() { var sandbox; var fake; var object; var originalBar; var originalFoo; function setupFakes(){ sandbox = sinon.createSandbox(); fake = sandbox.fake(); object = { foo() {}, bar(){} }; originalBar = object.bar; originalFoo = object.foo; sandbox.replace(object, "foo", fake); object.foo("Hi"); fakeBar = sandbox.stub(object, "bar"); object.bar("Hi, bar"); refute.isUndefined(object.foo.calledOnce); assert.isTrue(fake.calledOnce); assert.equals(fake.lastArg, "Hi"); assert.isTrue(fakeBar.calledOnce); } it("should remove all fakes from the objects on restore", function() { setupFakes(); sandbox.restore(); assert.isUndefined(object.foo.calledOnce); assert.equals(object.foo, originalFoo); assert.equals(object.bar, originalBar); }); it("should reset the history (and behaviour) on reset, but not remove fakes", function() { setupFakes(); sandbox.reset(); refute.isUndefined(object.foo.calledOnce); refute.isUndefined(object.bar.calledOnce); assert.isTrue(fake.notCalled); assert.isTrue(fakeBar.notCalled); refute.equals(fake.lastArg, "Hi"); // this shouldn't fail! }); /*it("should remove all fakes from the objects on restore", function() { setupFakes(); //sandbox.resetHistory(); //sandbox.resetBehavior(); sandbox.reset(); refute.defined(object.foo.calledOnce); assert.isTrue(fake.notCalled); refute.equals(fake.lastArg, "Hi"); }); */ });
Loading…

no comments

    sign in to comment