From 09469cae6f95d6576b9c14fb9cebb8c62105b5c7 Mon Sep 17 00:00:00 2001 From: robertjmason Date: Tue, 30 Jun 2015 13:00:53 -0700 Subject: [PATCH 1/3] Added arrayContaining()/ArrayContaining definitions --- jasmine/jasmine.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index 9e662c6e17..13160c4d2d 100644 --- a/jasmine/jasmine.d.ts +++ b/jasmine/jasmine.d.ts @@ -47,6 +47,7 @@ declare module jasmine { function any(aclass: any): Any; function anything(): Any; + function arrayContaining(sample: any[]): ArrayContaining; function objectContaining(sample: any): ObjectContaining; function createSpy(name: string, originalFn?: Function): Spy; function createSpyObj(baseName: string, methodNames: any[]): any; @@ -71,6 +72,13 @@ declare module jasmine { length: number; [n: number]: T; } + + interface ArrayContaining { + new (sample: any[]): any; + + asymmetricMatch(other: any): boolean; + jasmineToString(): string; + } interface ObjectContaining { new (sample: any): any; From 7b129ea9d405010b2180b14828c91c6e2dc18bf0 Mon Sep 17 00:00:00 2001 From: robertjmason Date: Tue, 30 Jun 2015 13:09:48 -0700 Subject: [PATCH 2/3] Added arrayContaining test --- jasmine/jasmine-tests.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index 1bdf964dd9..c4ad63e86c 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -657,6 +657,30 @@ describe("jasmine.objectContaining", function () { }); }); +describe("jasmine.arrayContaining", function() { + var foo; + + beforeEach(function() { + foo = [1, 2, 3, 4]; + }); + + it("matches arrays with some of the values", function() { + expect(foo).toEqual(jasmine.arrayContaining([3, 1])); + expect(foo).not.toEqual(jasmine.arrayContaining([6])); + }); + + describe("when used with a spy", function() { + it("is useful when comparing arguments", function() { + var callback = jasmine.createSpy('callback'); + + callback([1, 2, 3, 4]); + + expect(callback).toHaveBeenCalledWith(jasmine.arrayContaining([4, 2, 3])); + expect(callback).not.toHaveBeenCalledWith(jasmine.arrayContaining([5, 2])); + }); + }); +}); + describe("Manually ticking the Jasmine Clock", function () { var timerCallback: any; From d9b1c4d96c215ccf7770c5ba97348c7a713f26fb Mon Sep 17 00:00:00 2001 From: robertjmason Date: Tue, 30 Jun 2015 15:25:16 -0700 Subject: [PATCH 3/3] Added "any" type to foo Apparently the "noImplicitAny" switch is set in Travis. --- jasmine/jasmine-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index c4ad63e86c..d5eb228c95 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -658,7 +658,7 @@ describe("jasmine.objectContaining", function () { }); describe("jasmine.arrayContaining", function() { - var foo; + var foo: any; beforeEach(function() { foo = [1, 2, 3, 4];