Skip to content

Commit

Permalink
Add support for asymmetricMatch. (#37146)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfarrar authored and weswigham committed Jul 26, 2019
1 parent b12a305 commit b5d986a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
15 changes: 9 additions & 6 deletions types/jasmine/index.d.ts
Expand Up @@ -12,6 +12,7 @@
// Domas Trijonis <https://github.com/fdim>
// Peter Safranek <https://github.com/pe8ter>
// Moshe Kolodny <https://github.com/kolodny>
// Stephen Farrar <https://github.com/stephenfarrar>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
// For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts
Expand Down Expand Up @@ -179,10 +180,10 @@ declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, t
declare function waits(timeout?: number): void;

declare namespace jasmine {
type ExpectedRecursive<T> = T | ObjectContaining<T> | {
type ExpectedRecursive<T> = T | ObjectContaining<T> | AsymmetricMatcher | {
[K in keyof T]: ExpectedRecursive<T[K]> | Any;
};
type Expected<T> = T | ObjectContaining<T> | Any | Spy | {
type Expected<T> = T | ObjectContaining<T> | AsymmetricMatcher | Any | Spy | {
[K in keyof T]: ExpectedRecursive<T[K]>;
};
type SpyObjMethodNames<T = undefined> =
Expand Down Expand Up @@ -229,17 +230,19 @@ declare namespace jasmine {
jasmineToString(): string;
}

interface AsymmetricMatcher {
asymmetricMatch(other: any): boolean;
jasmineToString?(): string;
}

// taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
interface ArrayLike<T> {
length: number;
[n: number]: T;
}

interface ArrayContaining<T> {
interface ArrayContaining<T> extends AsymmetricMatcher {
new?(sample: ArrayLike<T>): ArrayLike<T>;

asymmetricMatch(other: any): boolean;
jasmineToString?(): string;
}

interface ObjectContaining<T> {
Expand Down
1 change: 1 addition & 0 deletions types/jasmine/jasmine-tests.ts
Expand Up @@ -847,6 +847,7 @@ describe('custom asymmetry', function() {

it('dives in deep', function() {
expect('foo,bar,baz,quux').toEqual(tester);
expect(123).not.toEqual(tester);
});

describe('when used with a spy', function() {
Expand Down
15 changes: 9 additions & 6 deletions types/jasmine/ts3.1/index.d.ts
Expand Up @@ -10,6 +10,7 @@
// Domas Trijonis <https://github.com/fdim>
// Peter Safranek <https://github.com/pe8ter>
// Moshe Kolodny <https://github.com/kolodny>
// Stephen Farrar <https://github.com/stephenfarrar>
// For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts

type ImplementationCallback = (() => Promise<any>) | ((done: DoneFn) => void);
Expand Down Expand Up @@ -182,10 +183,10 @@ declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, t
declare function waits(timeout?: number): void;

declare namespace jasmine {
type ExpectedRecursive<T> = T | ObjectContaining<T> | {
type ExpectedRecursive<T> = T | ObjectContaining<T> | AsymmetricMatcher | {
[K in keyof T]: ExpectedRecursive<T[K]> | Any;
};
type Expected<T> = T | ObjectContaining<T> | Any | Spy | {
type Expected<T> = T | ObjectContaining<T> | AsymmetricMatcher | Any | Spy | {
[K in keyof T]: ExpectedRecursive<T[K]>;
};
type SpyObjMethodNames<T = undefined> =
Expand Down Expand Up @@ -238,17 +239,19 @@ declare namespace jasmine {
jasmineToString(): string;
}

interface AsymmetricMatcher {
asymmetricMatch(other: any): boolean;
jasmineToString?(): string;
}

// taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
interface ArrayLike<T> {
length: number;
[n: number]: T;
}

interface ArrayContaining<T> {
interface ArrayContaining<T> extends AsymmetricMatcher {
new?(sample: ArrayLike<T>): ArrayLike<T>;

asymmetricMatch(other: any): boolean;
jasmineToString?(): string;
}

interface ObjectContaining<T> {
Expand Down
1 change: 1 addition & 0 deletions types/jasmine/ts3.1/jasmine-tests.ts
Expand Up @@ -849,6 +849,7 @@ describe('custom asymmetry', function() {

it('dives in deep', function() {
expect('foo,bar,baz,quux').toEqual(tester);
expect(123).not.toEqual(tester);
});

describe('when used with a spy', function() {
Expand Down

0 comments on commit b5d986a

Please sign in to comment.