Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias spy.reset to spy.resetHistory #1630

Merged
merged 4 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/release-source/release/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ 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.

Expand Down
7 changes: 5 additions & 2 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -100,7 +101,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.");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -413,6 +414,8 @@ function delegateToCalls(method, matchAny, actual, notCalled) {
};
}

spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg("reset"));

delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
delegateToCalls("calledWith", true);
Expand Down
2 changes: 1 addition & 1 deletion lib/sinon/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var proto = {
});
},

resetHistory: spy.reset,
resetHistory: spy.resetHistory,

reset: function () {
this.resetHistory();
Expand Down
10 changes: 5 additions & 5 deletions test/call-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ describe("sinonSpy.call", function () {
var spy = sinonSpy();
spy();

spy.reset();
spy.resetHistory();

assertReset(spy);
});
Expand All @@ -981,7 +981,7 @@ describe("sinonSpy.call", function () {
spies[0]();
spies[1]();

spies[0].reset();
spies[0].resetHistory();

assert(!spies[0].calledBefore(spies[1]));
});
Expand All @@ -995,7 +995,7 @@ describe("sinonSpy.call", function () {
spy("c");
var fakeC = spy.withArgs("c");

spy.reset();
spy.resetHistory();

assertReset(fakeA);
assertReset(fakeB);
Expand Down Expand Up @@ -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");
Expand All @@ -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");
});
Expand Down
6 changes: 3 additions & 3 deletions test/spy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2538,17 +2538,17 @@ describe("spy", function () {
});
});

describe(".reset", function () {
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");
Expand Down
2 changes: 1 addition & 1 deletion test/stub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/util/core/every-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down