diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index 877c7ed6e2..40706dec76 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Jasmine 3.3 +// Type definitions for Jasmine 3.4 // Project: http://jasmine.github.io // Definitions by: Boris Yankov // Theodore Brown @@ -13,6 +13,7 @@ // Peter Safranek // Moshe Kolodny // Stephen Farrar +// Mochamad Arfin // 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 @@ -199,6 +200,30 @@ declare namespace jasmine { function anything(): Any; + /** + * That will succeed if the actual value being compared is `true` or anything truthy. + * @since 3.1.0 + */ + function truthy(): Truthy; + + /** + * That will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey. + * @since 3.1.0 + */ + function falsy(): Falsy; + + /** + * That will succeed if the actual value being compared is empty. + * @since 3.1.0 + */ + function empty(): Empty; + + /** + * That will succeed if the actual value being compared is not empty. + * @since 3.1.0 + */ + function notEmpty(): NotEmpty; + function arrayContaining(sample: ArrayLike): ArrayContaining; function arrayWithExactContents(sample: ArrayLike): ArrayContaining; function objectContaining(sample: Partial): ObjectContaining; @@ -230,10 +255,15 @@ declare namespace jasmine { jasmineToString(): string; } - interface AsymmetricMatcher { + interface AsymmetricMatcher { asymmetricMatch(other: any): boolean; - jasmineToString?(): string; - } + jasmineToString?(): T; + } + + interface Truthy extends AsymmetricMatcher<''> { } + interface Falsy extends AsymmetricMatcher<''> { } + interface Empty extends AsymmetricMatcher<''> { } + interface NotEmpty extends AsymmetricMatcher<''> { } // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains() interface ArrayLike { @@ -246,7 +276,7 @@ declare namespace jasmine { } interface ObjectContaining { - new?(sample: Partial): Partial; + new?(sample: {[K in keyof T]?: any}): {[K in keyof T]?: any}; jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean; jasmineToString?(): string; diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 0169bfcef2..c6220c548f 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -1317,6 +1317,49 @@ describe("createSpyObj", function() { }); }); +describe('Static Matcher Test', function() { + it('Falsy', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.falsy(), + }) + ); + }); + it('Truthy', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.truthy(), + }) + ); + }); + it('Empty', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.empty(), + }) + ); + }); + it('NotEmpty', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.notEmpty(), + }) + ); + }); + it('Partial should OK', () => { + expect({ value: null, label: 'abcd' }).toEqual( + jasmine.objectContaining({ + value: jasmine.anything(), + }) + ); + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: 'any value should ok', + }) + ); + }); +}); + (() => { // from boot.js const env = jasmine.getEnv(); diff --git a/types/jasmine/ts3.1/index.d.ts b/types/jasmine/ts3.1/index.d.ts index 3d9288d7ca..e5f6799418 100644 --- a/types/jasmine/ts3.1/index.d.ts +++ b/types/jasmine/ts3.1/index.d.ts @@ -11,6 +11,7 @@ // Peter Safranek // Moshe Kolodny // Stephen Farrar +// Mochamad Arfin // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts type ImplementationCallback = (() => Promise) | ((done: DoneFn) => void); @@ -208,6 +209,30 @@ declare namespace jasmine { function anything(): Any; + /** + * That will succeed if the actual value being compared is `true` or anything truthy. + * @since 3.1.0 + */ + function truthy(): Truthy; + + /** + * That will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey. + * @since 3.1.0 + */ + function falsy(): Falsy; + + /** + * That will succeed if the actual value being compared is empty. + * @since 3.1.0 + */ + function empty(): Empty; + + /** + * That will succeed if the actual value being compared is not empty. + * @since 3.1.0 + */ + function notEmpty(): NotEmpty; + function arrayContaining(sample: ArrayLike): ArrayContaining; function arrayWithExactContents(sample: ArrayLike): ArrayContaining; function objectContaining(sample: Partial): ObjectContaining; @@ -239,10 +264,15 @@ declare namespace jasmine { jasmineToString(): string; } - interface AsymmetricMatcher { + interface AsymmetricMatcher { asymmetricMatch(other: any): boolean; - jasmineToString?(): string; - } + jasmineToString?(): T; + } + + interface Truthy extends AsymmetricMatcher<''> { } + interface Falsy extends AsymmetricMatcher<''> { } + interface Empty extends AsymmetricMatcher<''> { } + interface NotEmpty extends AsymmetricMatcher<''> { } // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains() interface ArrayLike { @@ -255,7 +285,7 @@ declare namespace jasmine { } interface ObjectContaining { - new?(sample: Partial): Partial; + new?(sample: {[K in keyof T]?: any}): {[K in keyof T]?: any}; jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean; jasmineToString?(): string; diff --git a/types/jasmine/ts3.1/jasmine-tests.ts b/types/jasmine/ts3.1/jasmine-tests.ts index d5a29020b9..90f5a53bd8 100644 --- a/types/jasmine/ts3.1/jasmine-tests.ts +++ b/types/jasmine/ts3.1/jasmine-tests.ts @@ -1398,6 +1398,49 @@ describe("createSpyObj", function() { }); }); +describe('Static Matcher Test', function() { + it('Falsy', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.falsy(), + }) + ); + }); + it('Truthy', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.truthy(), + }) + ); + }); + it('Empty', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.empty(), + }) + ); + }); + it('NotEmpty', () => { + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: jasmine.notEmpty(), + }) + ); + }); + it('Partial should OK', () => { + expect({ value: null, label: 'abcd' }).toEqual( + jasmine.objectContaining({ + value: jasmine.anything(), + }) + ); + expect({ value: null }).toEqual( + jasmine.objectContaining({ + value: 'any value should ok', + }) + ); + }); + }); + (() => { // from boot.js const env = jasmine.getEnv();