Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#4780 from robertjmason/master
Browse files Browse the repository at this point in the history
Add arrayContaining() definition/test
  • Loading branch information
vvakame committed Jul 3, 2015
2 parents 956b9a0 + d9b1c4d commit ab3cc82
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions jasmine/jasmine-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions jasmine/jasmine.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ab3cc82

Please sign in to comment.