From e870a640a8ff8f0e72013a0040ec417c6fe9807f Mon Sep 17 00:00:00 2001 From: GCHQDeveloper500 <32099399+GCHQDeveloper500@users.noreply.github.com> Date: Mon, 11 Dec 2017 12:34:52 +0000 Subject: [PATCH] Use deprecation helper and remove all references to 'reset' --- lib/sinon/spy.js | 7 ++++--- lib/sinon/stub.js | 2 +- test/call-test.js | 10 +++++----- test/spy-test.js | 8 -------- test/stub-test.js | 2 +- test/util/core/every-test.js | 2 +- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index e80cd22d7..a46c795aa 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -2,6 +2,7 @@ var createBehavior = require("./behavior").create; var extend = require("./util/core/extend"); +var deprecated = require("./util/core/deprecated"); var functionName = require("./util/core/function-name"); var functionToString = require("./util/core/function-to-string"); var getPropertyDescriptor = require("./util/core/get-property-descriptor"); @@ -32,7 +33,7 @@ function spy(object, property, types) { return spy.create(function () { }); } - if (!types) { + if (!types) { return wrapMethod(object, property, spy.create(object[property])); } @@ -156,7 +157,7 @@ var spyApi = { delete proxy.create; extend(proxy, func); - proxy.reset(); + proxy.resetHistory(); proxy.prototype = func.prototype; proxy.displayName = name || "spy"; proxy.toString = functionToString; @@ -413,7 +414,7 @@ function delegateToCalls(method, matchAny, actual, notCalled) { }; } -spyApi.reset = spyApi.resetHistory; +spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg('reset')); delegateToCalls("calledOn", true); delegateToCalls("alwaysCalledOn", false, "calledOn"); diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index a21544d83..c7c5e2614 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -132,7 +132,7 @@ var proto = { }); }, - resetHistory: spy.reset, + resetHistory: spy.resetHistory, reset: function () { this.resetHistory(); diff --git a/test/call-test.js b/test/call-test.js index d2462db41..f720de7bd 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -971,7 +971,7 @@ describe("sinonSpy.call", function () { var spy = sinonSpy(); spy(); - spy.reset(); + spy.resetHistory(); assertReset(spy); }); @@ -981,7 +981,7 @@ describe("sinonSpy.call", function () { spies[0](); spies[1](); - spies[0].reset(); + spies[0].resetHistory(); assert(!spies[0].calledBefore(spies[1])); }); @@ -995,7 +995,7 @@ describe("sinonSpy.call", function () { spy("c"); var fakeC = spy.withArgs("c"); - spy.reset(); + spy.resetHistory(); assertReset(fakeA); assertReset(fakeB); @@ -1288,7 +1288,7 @@ describe("sinonSpy.call", function () { "\n\n spy(" + str + ")" + "\n\n spy(" + str + ")"); - spy.reset(); + spy.resetHistory(); spy("test"); spy("spy\ntest"); @@ -1306,7 +1306,7 @@ describe("sinonSpy.call", function () { spy(); assert.equals(spy.printf("%t"), "undefined"); - spy.reset(); + spy.resetHistory(); spy.call(true); assert.equals(spy.printf("%t"), "true"); }); diff --git a/test/spy-test.js b/test/spy-test.js index 21ca28926..132032483 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -2538,14 +2538,6 @@ describe("spy", function () { }); }); - describe(".reset", function () { - it("is alias for resetHistory", function () { - var spy = createSpy(); - - assert.same(spy.reset, spy.resetHistory); - }); - }); - describe(".resetHistory", function () { it("return same object", function () { var spy = createSpy(); diff --git a/test/stub-test.js b/test/stub-test.js index 5b225e9ee..c8962a2fe 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -607,7 +607,7 @@ describe("stub", function () { this.originalError = global.Error; errorSpy = createSpy(global, "Error"); // errorSpy starts with a call already made, not sure why - errorSpy.reset(); + errorSpy.resetHistory(); }); afterEach(function () { diff --git a/test/util/core/every-test.js b/test/util/core/every-test.js index 0a084a054..549ef64f8 100644 --- a/test/util/core/every-test.js +++ b/test/util/core/every-test.js @@ -34,7 +34,7 @@ describe("util/core/every", function () { every(iterableOne, callback); assert.equals(callback.callCount, 4); - callback.reset(); + callback.resetHistory(); every(iterableTwo, callback); assert.equals(callback.callCount, 3);