diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index 01e734068f..02185cdbe4 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -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 { diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 100bed9fee..280f3658cd 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -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", () => { diff --git a/types/jasmine/ts3.1/index.d.ts b/types/jasmine/ts3.1/index.d.ts index d27f386d04..2f135cc699 100644 --- a/types/jasmine/ts3.1/index.d.ts +++ b/types/jasmine/ts3.1/index.d.ts @@ -953,6 +953,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 { diff --git a/types/jasmine/ts3.1/jasmine-tests.ts b/types/jasmine/ts3.1/jasmine-tests.ts index 96b5fc48c5..f8eabd65b5 100644 --- a/types/jasmine/ts3.1/jasmine-tests.ts +++ b/types/jasmine/ts3.1/jasmine-tests.ts @@ -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", () => { diff --git a/types/jasmine/v2/index.d.ts b/types/jasmine/v2/index.d.ts index e22aca8618..5c43ae4d4d 100644 --- a/types/jasmine/v2/index.d.ts +++ b/types/jasmine/v2/index.d.ts @@ -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 { diff --git a/types/jasmine/v2/jasmine-tests.ts b/types/jasmine/v2/jasmine-tests.ts index 9dc67c8e8d..199a24f2f9 100644 --- a/types/jasmine/v2/jasmine-tests.ts +++ b/types/jasmine/v2/jasmine-tests.ts @@ -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", () => {