diff --git a/types/jest-diff/index.d.ts b/types/jest-diff/index.d.ts new file mode 100644 index 0000000000..b296c07f91 --- /dev/null +++ b/types/jest-diff/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for jest-diff 20.0 +// Project: https://github.com/facebook/jest/tree/master/packages/jest-diff +// Definitions by: Alex Coles +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace diff { + interface DiffOptions { + aAnnotation?: string; + bAnnotation?: string; + expand?: boolean; + contextLines?: number; + } +} + +declare function diff(a: any, b: any, options?: diff.DiffOptions): string; + +export = diff; diff --git a/types/jest-diff/jest-diff-tests.ts b/types/jest-diff/jest-diff-tests.ts new file mode 100644 index 0000000000..01e0453e61 --- /dev/null +++ b/types/jest-diff/jest-diff-tests.ts @@ -0,0 +1,42 @@ +import diff = require('jest-diff'); + +diff([], ['a']); // $ExpectType string +diff(false, true); +diff(null, null); +diff(1000, 1001); +diff(/d+/, /w+/); +diff(new Map(), new Map()); +diff(new Set(), new Set()); +diff(new Date(), new Date()); +diff('ts', 'js'); +diff(Symbol(), Symbol(1)); +diff(undefined, undefined); + +diff([], ['a'], { }); // $ExpectType string +diff([], ['a'], { expand: false }); // $ExpectType string +diff([], ['a'], { contextLines: 3 }); // $ExpectType string +// $ExpectType string +diff([], ['a'], { + aAnnotation: 'esperado', + bAnnotation: 'recibido' +}); + +diff(); // $ExpectError +diff([]); // $ExpectError +// diff([], {}, []); // $ExpectError (does not error on 2.3) + +diff([], ['a'], { expand: false }); // $ExpectType string +diff([], ['a'], { contextLines: 3 }); // $ExpectType string +// $ExpectType string +diff([], ['a'], { + aAnnotation: 'esperado', + bAnnotation: 'recibido' +}); + +// $ExpectError +diff([], ['a'], { + expand: 'yeah', + aAnnotation: false, + bAnnotation: {}, + contextLines: 'two' +}); diff --git a/types/jest-diff/tsconfig.json b/types/jest-diff/tsconfig.json new file mode 100644 index 0000000000..3624e1778b --- /dev/null +++ b/types/jest-diff/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jest-diff-tests.ts" + ] +} diff --git a/types/jest-diff/tslint.json b/types/jest-diff/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/jest-diff/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/jest-get-type/index.d.ts b/types/jest-get-type/index.d.ts new file mode 100644 index 0000000000..e43fbcf7ab --- /dev/null +++ b/types/jest-get-type/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for jest-get-type 21.0 +// Project: https://github.com/facebook/jest/tree/master/packages/jest-get-type +// Definitions by: Alex Coles +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace getType { + type ValueType = + | 'array' + | 'boolean' + | 'function' + | 'null' + | 'number' + | 'object' + | 'regexp' + | 'map' + | 'set' + | 'date' + | 'string' + | 'symbol' + | 'undefined'; +} + +declare function getType(value: any): getType.ValueType; + +export = getType; diff --git a/types/jest-get-type/jest-get-type-tests.ts b/types/jest-get-type/jest-get-type-tests.ts new file mode 100644 index 0000000000..6c423adcc9 --- /dev/null +++ b/types/jest-get-type/jest-get-type-tests.ts @@ -0,0 +1,17 @@ +import getType = require('jest-get-type'); + +getType([]); // $ExpectType ValueType +getType(false); +getType(null); +getType(1000); +getType(/d+/); +getType(new Map()); +getType(new Set()); +getType(new Date()); +getType('ts'); +getType(Symbol()); +getType(undefined); + +getType(); // $ExpectError +getType([], undefined); // $ExpectError +getType([], ''); // $ExpectError diff --git a/types/jest-get-type/tsconfig.json b/types/jest-get-type/tsconfig.json new file mode 100644 index 0000000000..d1e6fac5ee --- /dev/null +++ b/types/jest-get-type/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jest-get-type-tests.ts" + ] +} diff --git a/types/jest-get-type/tslint.json b/types/jest-get-type/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/jest-get-type/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/jest-matcher-utils/index.d.ts b/types/jest-matcher-utils/index.d.ts new file mode 100644 index 0000000000..92bc13070b --- /dev/null +++ b/types/jest-matcher-utils/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for jest-matcher-utils 21.0 +// Project: https://github.com/facebook/jest/tree/master/packages/jest-get-type +// Definitions by: Alex Coles +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import * as chalk from 'chalk'; + +export const EXPECTED_COLOR: chalk.ChalkChain; +export const RECEIVED_COLOR: chalk.ChalkChain; +export const EXPECTED_BG: chalk.ChalkChain; // TODO: removed in b430e51a +export const RECEIVED_BG: chalk.ChalkChain; // TODO: removed in b430e51a +export const SUGGEST_TO_EQUAL: string; + +export function stringify(object: any, maxDepth?: number): string; + +export function highlightTrailingWhitespace( + text: string, + bgColor: chalk.ChalkChain // removed in b430e51a +): string; + +export function printReceived(object: any): string; +export function printExpected(value: any): string; +export function printWithType( + name: string, + received: any, + print: (value: any) => string +): string; + +export function ensureNoExpected(actual: any, matcherName?: string): void; +export function ensureActualIsNumber(actual: any, matcherName?: string): void; +export function ensureExpectedIsNumber(actual: any, matcherName?: string): void; +export function ensureNumbers( + actual: any, + expected: any, + matcherName?: string +): void; + +export function pluralize(word: string, count: number): string; +export function matcherHint( + matcherName: string, + received?: string, + expected?: string, + options?: { secondArgument?: string; isDirectExpectCall?: boolean } +): string; diff --git a/types/jest-matcher-utils/jest-matcher-utils-tests.ts b/types/jest-matcher-utils/jest-matcher-utils-tests.ts new file mode 100644 index 0000000000..6f9a4ddeab --- /dev/null +++ b/types/jest-matcher-utils/jest-matcher-utils-tests.ts @@ -0,0 +1,57 @@ +import * as chalk from 'chalk'; +import * as utils from 'jest-matcher-utils'; + +utils.EXPECTED_COLOR; // $ExpectType ChalkChain +utils.RECEIVED_COLOR; // $ExpectType ChalkChain +utils.SUGGEST_TO_EQUAL; // $ExpectType string + +utils.stringify({}); // $ExpectType string +utils.stringify({}, 44); +utils.stringify({}, '44'); // $ExpectError +utils.stringify({}, false); // $ExpectError + +utils.highlightTrailingWhitespace('', chalk.red); // $ExpectType string +utils.highlightTrailingWhitespace(44, chalk.blue); // $ExpectError +utils.highlightTrailingWhitespace(false, chalk.green); // $ExpectError + +utils.printReceived({}); // $ExpectType string +utils.printExpected({}); // $ExpectType string +utils.printWithType('obj', {}, () => ''); // $ExpectType string + +utils.ensureNoExpected(null, ''); // $ExpectType void +utils.ensureNoExpected('', ''); + +utils.ensureActualIsNumber(66); // $ExpectType void +utils.ensureActualIsNumber(66, 'highwayRouteMatcher'); +utils.ensureActualIsNumber('66', 'highwayRouteMatcher'); + +utils.ensureExpectedIsNumber(66); // $ExpectType void +utils.ensureExpectedIsNumber(66, 'highwayRouteMatcher'); +utils.ensureExpectedIsNumber('66', 'highwayRouteMatcher'); + +utils.ensureNumbers(66, 66); // $ExpectType void +utils.ensureNumbers(66, 66, 'highwayRouteMatcher'); +utils.ensureNumbers('66', 'highwayRouteMatcher'); +utils.ensureNumbers(66); // $ExpectError + +utils.pluralize('fox', 1); // $ExpectType string +utils.pluralize('fox', 9); +utils.pluralize('fox', 'a yuge number'); // $ExpectError +utils.pluralize(1, 2); // $ExpectError + +utils.matcherHint('[.not]primeNumberMatcher'); // $ExpectType string +utils.matcherHint('[.not]primeNumberMatcher', '12'); +utils.matcherHint('[.not]primeNumberMatcher', '12', '13'); +utils.matcherHint('[.not]primeNumberMatcher', '12', '13', {}); +utils.matcherHint('[.not]primeNumberMatcher', '12', '13', { + secondArgument: '' +}); +utils.matcherHint('[.not]primeNumberMatcher', '12', '13', { + secondArgument: '', + isDirectExpectCall: true +}); +utils.matcherHint('[.not]primeNumberMatcher', '12', '13', { + secondArgument: '', + isDirectExpectCall: true, + notAnOption: 'notAnOptionValue' // $ExpectError +}); diff --git a/types/jest-matcher-utils/tsconfig.json b/types/jest-matcher-utils/tsconfig.json new file mode 100644 index 0000000000..115b762386 --- /dev/null +++ b/types/jest-matcher-utils/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jest-matcher-utils-tests.ts" + ] +} diff --git a/types/jest-matcher-utils/tslint.json b/types/jest-matcher-utils/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/jest-matcher-utils/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}