From cc6f3a564644daeab17f2933118ace6adcb87844 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 19 May 2020 05:22:17 +1000 Subject: [PATCH] Update comparison methods to support BigInt (#44368) As per https://github.com/facebook/jest/pull/8382 TypeScript 3.2+ supports BigInt with esnext target. TypeScript 3.8+ supports it with es2020 target. dtslint is very particular on how the `typesVersions` should be handled, hence the code duplication. --- types/jest/package.json | 4 ++++ types/jest/ts3.2/index.d.ts | 23 +++++++++++++++++++++++ types/jest/ts3.2/jest-tests.ts | 13 +++++++++++++ types/jest/ts3.2/tsconfig.json | 20 ++++++++++++++++++++ types/jest/ts3.2/tslint.json | 6 ++++++ 5 files changed, 66 insertions(+) create mode 100644 types/jest/ts3.2/index.d.ts create mode 100644 types/jest/ts3.2/jest-tests.ts create mode 100644 types/jest/ts3.2/tsconfig.json create mode 100644 types/jest/ts3.2/tslint.json diff --git a/types/jest/package.json b/types/jest/package.json index d2dd38a8831b4ed..dc5864c662aaf06 100644 --- a/types/jest/package.json +++ b/types/jest/package.json @@ -3,5 +3,9 @@ "dependencies": { "jest-diff": "^25.2.1", "pretty-format": "^25.2.1" + }, + "types": "index", + "typesVersions": { + ">=3.2.0-0": { "*": ["ts3.2/*"] } } } diff --git a/types/jest/ts3.2/index.d.ts b/types/jest/ts3.2/index.d.ts new file mode 100644 index 000000000000000..8dbfc0e7c60fa16 --- /dev/null +++ b/types/jest/ts3.2/index.d.ts @@ -0,0 +1,23 @@ +// tslint:disable-next-line:no-bad-reference +/// + +declare namespace jest { + interface Matchers { + /** + * For comparing numbers or big integer values. + */ + toBeGreaterThan(expected: number | bigint): R; + /** + * For comparing numbers or big integer values. + */ + toBeGreaterThanOrEqual(expected: number | bigint): R; + /** + * For comparing numbers or big integer values. + */ + toBeLessThan(expected: number | bigint): R; + /** + * For comparing numbers or big integer values. + */ + toBeLessThanOrEqual(expected: number | bigint): R; + } +} diff --git a/types/jest/ts3.2/jest-tests.ts b/types/jest/ts3.2/jest-tests.ts new file mode 100644 index 000000000000000..b53c5b1f8682020 --- /dev/null +++ b/types/jest/ts3.2/jest-tests.ts @@ -0,0 +1,13 @@ +/* Basic matchers */ + +describe('', () => { + it('', () => { + expect(BigInt(0)).toBeGreaterThan(BigInt(1)); + + expect(BigInt(0)).toBeGreaterThanOrEqual(BigInt(1)); + + expect(BigInt(0)).toBeLessThan(BigInt(1)); + + expect(BigInt(0)).toBeLessThanOrEqual(BigInt(1)); + }); +}); diff --git a/types/jest/ts3.2/tsconfig.json b/types/jest/ts3.2/tsconfig.json new file mode 100644 index 000000000000000..dc2701483baba15 --- /dev/null +++ b/types/jest/ts3.2/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["dom", "es6", "esnext", "es2020"], + "noImplicitAny": true, + "noImplicitThis": false, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": ["../../"], + "target": "esnext", + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jest-tests.ts" + ] +} diff --git a/types/jest/ts3.2/tslint.json b/types/jest/ts3.2/tslint.json new file mode 100644 index 000000000000000..ad93d8fc0d9ca6b --- /dev/null +++ b/types/jest/ts3.2/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-unnecessary-generics": false + } +} \ No newline at end of file