Skip to content

Commit 94a6752

Browse files
authored
fix(expect): add type definitions for asymmetric closeTo matcher (#12304)
1 parent f2f578f commit 94a6752

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[expect]` Add type definitions for asymmetric `closeTo` matcher ([#12304](https://github.com/facebook/jest/pull/12304))
8+
79
### Chore & Maintenance
810

911
### Performance

packages/expect/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ interface AsymmetricMatchers {
7474
any(sample: unknown): AsymmetricMatcher;
7575
anything(): AsymmetricMatcher;
7676
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
77+
closeTo(sample: number, precision?: number): AsymmetricMatcher;
7778
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
7879
stringContaining(sample: string): AsymmetricMatcher;
7980
stringMatching(sample: string | RegExp): AsymmetricMatcher;

packages/jest-types/__typetests__/expect.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ expectType<void>(expect(['B']).toEqual(expect.not.arrayContaining(['A'])));
2525
expectError(expect(['A']).toEqual(expect.not.arrayContaining('A')));
2626
expectError(expect(['A']).toEqual(expect.not.arrayContaining()));
2727

28+
expectType<void>(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3)));
29+
expectType<void>(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3, 5)));
30+
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo('three')));
31+
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3, false)));
32+
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo()));
33+
expectType<void>(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3)));
34+
expectType<void>(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3, 5)));
35+
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo('three')));
36+
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3, false)));
37+
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo()));
38+
2839
expectType<void>(expect({a: 1}).toEqual(expect.objectContaining({a: 1})));
2940
expectError(expect({a: 1}).toEqual(expect.objectContaining(1)));
3041
expectError(expect({a: 1}).toEqual(expect.objectContaining()));

0 commit comments

Comments
 (0)