Skip to content

Commit bb1c089

Browse files
committed
Update comparison methods to support BigInt
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.
1 parent cc1de99 commit bb1c089

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

types/jest/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
"dependencies": {
44
"jest-diff": "^25.2.1",
55
"pretty-format": "^25.2.1"
6+
},
7+
"types": "index",
8+
"typesVersions": {
9+
">=3.2.0-0": { "*": ["ts3.2/*"] }
610
}
711
}

types/jest/ts3.2/index.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// tslint:disable-next-line:no-bad-reference
2+
/// <reference path="../index.d.ts" />
3+
4+
declare namespace jest {
5+
interface Matchers<R, T = {}> {
6+
/**
7+
* For comparing numbers or big integer values.
8+
*/
9+
toBeGreaterThan(expected: number | bigint): R;
10+
/**
11+
* For comparing numbers or big integer values.
12+
*/
13+
toBeGreaterThanOrEqual(expected: number | bigint): R;
14+
/**
15+
* For comparing numbers or big integer values.
16+
*/
17+
toBeLessThan(expected: number | bigint): R;
18+
/**
19+
* For comparing numbers or big integer values.
20+
*/
21+
toBeLessThanOrEqual(expected: number | bigint): R;
22+
}
23+
}

types/jest/ts3.2/jest-tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Basic matchers */
2+
3+
describe('', () => {
4+
it('', () => {
5+
expect(BigInt(0)).toBeGreaterThan(BigInt(1));
6+
7+
expect(BigInt(0)).toBeGreaterThanOrEqual(BigInt(1));
8+
9+
expect(BigInt(0)).toBeLessThan(BigInt(1));
10+
11+
expect(BigInt(0)).toBeLessThanOrEqual(BigInt(1));
12+
});
13+
});

types/jest/ts3.2/tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["dom", "es6", "esnext", "es2020"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": false,
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true,
9+
"baseUrl": "../../",
10+
"typeRoots": ["../../"],
11+
"target": "esnext",
12+
"types": [],
13+
"noEmit": true,
14+
"forceConsistentCasingInFileNames": true
15+
},
16+
"files": [
17+
"index.d.ts",
18+
"jest-tests.ts"
19+
]
20+
}

types/jest/ts3.2/tslint.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "dtslint/dt.json",
3+
"rules": {
4+
"no-unnecessary-generics": false
5+
}
6+
}

0 commit comments

Comments
 (0)