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 #1628

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/release-source/release/spies.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,13 @@ 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.resetHistory();`

#### `spy.restore()`

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

spyApi.reset = spyApi.resetHistory;

delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
delegateToCalls("calledWith", true);
Expand Down
12 changes: 10 additions & 2 deletions test/spy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down