From aed6042848fb5d92cb4109b29719f3b4d3d98bf4 Mon Sep 17 00:00:00 2001 From: Alex Povar <1074182+zvirja@users.noreply.github.com> Date: Thu, 10 Oct 2019 21:59:32 +0200 Subject: [PATCH] Allow to use argument matchers in withArgs() (#38738) --- types/jasmine/jasmine-tests.ts | 3 +++ types/jasmine/ts3.1/index.d.ts | 2 +- types/jasmine/ts3.1/jasmine-tests.ts | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 01413d84b9..082c99cac4 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -998,6 +998,7 @@ describe("jasmine.objectContaining", () => { describe("when used with a spy", () => { it("is useful for comparing arguments", () => { const callback = jasmine.createSpy('callback'); + callback.withArgs(jasmine.objectContaining({ bar: "foo" })).and.returnValue(42); callback({ bar: "baz" @@ -1040,6 +1041,7 @@ describe("jasmine.arrayContaining", () => { describe("when used with a spy", () => { it("is useful when comparing arguments", () => { const callback = jasmine.createSpy('callback'); + callback.withArgs(jasmine.arrayContaining([1, 2])).and.returnValue(42); callback([1, 2, 3, 4]); @@ -1067,6 +1069,7 @@ describe("jasmine.arrayWithExactContents", () => { describe("when used with a spy", () => { it("is useful when comparing arguments", () => { const callback = jasmine.createSpy('callback'); + callback.withArgs(jasmine.arrayWithExactContents([1, 2])).and.returnValue(42); callback([1, 2, 3, 4]); diff --git a/types/jasmine/ts3.1/index.d.ts b/types/jasmine/ts3.1/index.d.ts index d31eca1899..c048ea9bc6 100644 --- a/types/jasmine/ts3.1/index.d.ts +++ b/types/jasmine/ts3.1/index.d.ts @@ -825,7 +825,7 @@ declare namespace jasmine { and: SpyAnd; calls: Calls; - withArgs(...args: Parameters): Spy; + withArgs(...args: MatchableArgs): Spy; } type SpyObj = T & { diff --git a/types/jasmine/ts3.1/jasmine-tests.ts b/types/jasmine/ts3.1/jasmine-tests.ts index 8002276514..189245bef8 100644 --- a/types/jasmine/ts3.1/jasmine-tests.ts +++ b/types/jasmine/ts3.1/jasmine-tests.ts @@ -997,7 +997,8 @@ describe("jasmine.objectContaining", () => { describe("when used with a spy", () => { it("is useful for comparing arguments", () => { - const callback = jasmine.createSpy<(arg: { bar: string }) => void>('callback'); + const callback = jasmine.createSpy<(arg: { bar: string }) => number>('callback'); + callback.withArgs(jasmine.objectContaining({ bar: "foo" })).and.returnValue(42); callback({ bar: "baz" @@ -1039,7 +1040,8 @@ describe("jasmine.arrayContaining", () => { describe("when used with a spy", () => { it("is useful when comparing arguments", () => { - const callback = jasmine.createSpy<(numbers: number[]) => void>('callback'); + const callback = jasmine.createSpy<(numbers: number[]) => number>('callback'); + callback.withArgs(jasmine.arrayContaining([1, 2])).and.returnValue(42); callback([1, 2, 3, 4]); @@ -1066,7 +1068,8 @@ describe("jasmine.arrayWithExactContents", () => { describe("when used with a spy", () => { it("is useful when comparing arguments", () => { - const callback = jasmine.createSpy<(arg: number[]) => void>('callback'); + const callback = jasmine.createSpy<(arg: number[]) => number>('callback'); + callback.withArgs(jasmine.arrayWithExactContents([1, 2])).and.returnValue(42); callback([1, 2, 3, 4]);