Skip to content

Commit

Permalink
fix(expect): add type definitions for asymmetric closeTo matcher (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Feb 6, 2022
1 parent f2f578f commit 94a6752
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[expect]` Add type definitions for asymmetric `closeTo` matcher ([#12304](https://github.com/facebook/jest/pull/12304))

### Chore & Maintenance

### Performance
Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface AsymmetricMatchers {
any(sample: unknown): AsymmetricMatcher;
anything(): AsymmetricMatcher;
arrayContaining(sample: Array<unknown>): AsymmetricMatcher;
closeTo(sample: number, precision?: number): AsymmetricMatcher;
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher;
stringContaining(sample: string): AsymmetricMatcher;
stringMatching(sample: string | RegExp): AsymmetricMatcher;
Expand Down
11 changes: 11 additions & 0 deletions packages/jest-types/__typetests__/expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ expectType<void>(expect(['B']).toEqual(expect.not.arrayContaining(['A'])));
expectError(expect(['A']).toEqual(expect.not.arrayContaining('A')));
expectError(expect(['A']).toEqual(expect.not.arrayContaining()));

expectType<void>(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3)));
expectType<void>(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3, 5)));
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo('three')));
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3, false)));
expectError(expect(0.1 + 0.2).toEqual(expect.closeTo()));
expectType<void>(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3)));
expectType<void>(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3, 5)));
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo('three')));
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3, false)));
expectError(expect(0.1 + 0.2).toEqual(expect.not.closeTo()));

expectType<void>(expect({a: 1}).toEqual(expect.objectContaining({a: 1})));
expectError(expect({a: 1}).toEqual(expect.objectContaining(1)));
expectError(expect({a: 1}).toEqual(expect.objectContaining()));
Expand Down

0 comments on commit 94a6752

Please sign in to comment.