diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index 1bdf964dd91e16..d5eb228c952aff 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: any; + + 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; diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index 9e662c6e17760d..13160c4d2dc07d 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;