Skip to content

Commit

Permalink
Update comparison methods to support BigInt (#44368)
Browse files Browse the repository at this point in the history
As per jestjs/jest#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.
  • Loading branch information
D4nte authored May 18, 2020
1 parent 4904929 commit ea0b201
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions types/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"dependencies": {
"jest-diff": "^25.2.1",
"pretty-format": "^25.2.1"
},
"types": "index",
"typesVersions": {
">=3.2.0-0": { "*": ["ts3.2/*"] }
}
}
23 changes: 23 additions & 0 deletions types/jest/ts3.2/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// tslint:disable-next-line:no-bad-reference
/// <reference path="../index.d.ts" />

declare namespace jest {
interface Matchers<R, T = {}> {
/**
* 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;
}
}
13 changes: 13 additions & 0 deletions types/jest/ts3.2/jest-tests.ts
Original file line number Diff line number Diff line change
@@ -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));
});
});
20 changes: 20 additions & 0 deletions types/jest/ts3.2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
6 changes: 6 additions & 0 deletions types/jest/ts3.2/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-unnecessary-generics": false
}
}

0 comments on commit ea0b201

Please sign in to comment.