[jasmine-3.1] Add thesaveArgumentsByValue function (#45049)

See 15f969bee7/src/core/CallTracker.js\#L117 for definition

Co-authored-by: Robert Webb <robertwebb@google.com>
This commit is contained in:
Robert Webb 2020-06-21 22:51:11 -07:00 committed by GitHub
parent c5d5f696b2
commit 2a3191d028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 0 deletions

View File

@ -914,6 +914,8 @@ declare namespace jasmine {
first(): CallInfo;
/** By chaining the spy with calls.reset(), will clears all tracking for a spy */
reset(): void;
/** Set this spy to do a shallow clone of arguments passed to each invocation. */
saveArgumentsByValue(): void;
}
interface CallInfo {

View File

@ -794,6 +794,18 @@ describe("A spy", () => {
expect(foo.setBar.calls.any()).toBe(false);
});
it("can save arguments by value.", () => {
const arr = [1];
foo.setBar.calls.saveArgumentsByValue();
foo.setBar(arr);
arr.push(2);
foo.setBar(arr);
expect(foo.setBar.calls.argsFor(0)[0]).toEqual([1]);
expect(foo.setBar.calls.argsFor(1)[0]).toEqual([1, 2]);
});
});
describe("A spy, when created manually", () => {

View File

@ -953,6 +953,8 @@ declare namespace jasmine {
first(): CallInfo<Fn>;
/** By chaining the spy with calls.reset(), will clears all tracking for a spy */
reset(): void;
/** Set this spy to do a shallow clone of arguments passed to each invocation. */
saveArgumentsByValue(): void;
}
interface CallInfo<Fn extends Func> {

View File

@ -794,6 +794,18 @@ describe("A spy", () => {
expect(foo.setBar.calls.any()).toBe(false);
});
it("can save arguments by value.", () => {
const arr = [1];
foo.setBar.calls.saveArgumentsByValue();
foo.setBar(arr);
arr.push(2);
foo.setBar(arr);
expect(foo.setBar.calls.argsFor(0)[0]).toEqual([1]);
expect(foo.setBar.calls.argsFor(1)[0]).toEqual([1, 2]);
});
});
describe("A spy, when created manually", () => {

View File

@ -669,6 +669,8 @@ declare namespace jasmine {
first(): CallInfo;
/** By chaining the spy with calls.reset(), will clears all tracking for a spy **/
reset(): void;
/** Set this spy to do a shallow clone of arguments passed to each invocation. */
saveArgumentsByValue(): void;
}
interface CallInfo {

View File

@ -610,6 +610,18 @@ describe("A spy", () => {
expect(foo.setBar.calls.any()).toBe(false);
});
it("can save arguments by value.", () => {
const arr = [1];
foo.setBar.calls.saveArgumentsByValue();
foo.setBar(arr);
arr.push(2);
foo.setBar(arr);
expect(foo.setBar.calls.argsFor(0)[0]).toEqual([1]);
expect(foo.setBar.calls.argsFor(1)[0]).toEqual([1, 2]);
});
});
describe("A spy, when created manually", () => {