From d9fe288b89a525029488512fbffc5295affb0936 Mon Sep 17 00:00:00 2001 From: GCHQDeveloper500 <32099399+GCHQDeveloper500@users.noreply.github.com> Date: Fri, 8 Dec 2017 16:09:53 +0000 Subject: [PATCH 1/4] Alias spy.reset to spy.resetHistory --- docs/release-source/release/spies.md | 7 ++++++- lib/sinon/spy.js | 4 +++- test/spy-test.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/release-source/release/spies.md b/docs/release-source/release/spies.md index 49a41d978..604514922 100644 --- a/docs/release-source/release/spies.md +++ b/docs/release-source/release/spies.md @@ -390,11 +390,16 @@ Array of return values, `spy.returnValues[0]` is the return value of the first c If the call did not explicitly return a value, the value at the call's location in `.returnValues` will be `undefined`. -#### `spy.reset()` +#### `spy.resetHistory()` Resets the state of a spy. +#### `spy.reset()` + +Alias for `spy.reset();` + + #### `spy.restore()` Replaces the spy with the original method. Only available if the spy replaced an existing method. diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index f2105c0cd..e80cd22d7 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -100,7 +100,7 @@ var uuid = 0; var spyApi = { formatters: require("./spy-formatters"), - reset: function () { + resetHistory: function () { if (this.invoking) { var err = new Error("Cannot reset Sinon function while invoking it. " + "Move the call to .reset outside of the callback."); @@ -413,6 +413,8 @@ function delegateToCalls(method, matchAny, actual, notCalled) { }; } +spyApi.reset = spyApi.resetHistory; + delegateToCalls("calledOn", true); delegateToCalls("alwaysCalledOn", false, "calledOn"); delegateToCalls("calledWith", true); diff --git a/test/spy-test.js b/test/spy-test.js index dc68d6d7f..21ca28926 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -2539,16 +2539,24 @@ 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(); - var reset = spy.reset(); + var reset = spy.resetHistory(); assert(reset === spy); }); it("throws if called during spy invocation", function () { var spy = createSpy(function () { - spy.reset(); + spy.resetHistory(); }); assert.exception(spy, "InvalidResetException"); From 8cd3bf4a83cbcd3f1de169e86d5442a6d9bf2d77 Mon Sep 17 00:00:00 2001 From: GCHQDeveloper500 <32099399+GCHQDeveloper500@users.noreply.github.com> Date: Mon, 11 Dec 2017 10:54:50 +0000 Subject: [PATCH 2/4] Remove reference to 'reset' from docs --- docs/release-source/release/spies.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/release-source/release/spies.md b/docs/release-source/release/spies.md index 604514922..62e985d87 100644 --- a/docs/release-source/release/spies.md +++ b/docs/release-source/release/spies.md @@ -395,11 +395,6 @@ If the call did not explicitly return a value, the value at the call's location Resets the state of a spy. -#### `spy.reset()` - -Alias for `spy.reset();` - - #### `spy.restore()` Replaces the spy with the original method. Only available if the spy replaced an existing method. 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 3/4] 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); From 5e131b3e0a88eb703db551d4cbbb8b45f8c25d91 Mon Sep 17 00:00:00 2001 From: GCHQDeveloper500 <32099399+GCHQDeveloper500@users.noreply.github.com> Date: Mon, 11 Dec 2017 12:35:47 +0000 Subject: [PATCH 4/4] Single quotes on strings --- lib/sinon/spy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index a46c795aa..89281afa6 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -33,7 +33,7 @@ function spy(object, property, types) { return spy.create(function () { }); } - if (!types) { + if (!types) { return wrapMethod(object, property, spy.create(object[property])); } @@ -414,7 +414,7 @@ function delegateToCalls(method, matchAny, actual, notCalled) { }; } -spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg('reset')); +spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg("reset")); delegateToCalls("calledOn", true); delegateToCalls("alwaysCalledOn", false, "calledOn");