From 70d7a74681fc381e6ab3a3a1f919ea84a758b2a9 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Sat, 5 Feb 2022 19:26:02 +0200 Subject: [PATCH 1/2] fix: add closeTo typings --- packages/expect/src/types.ts | 1 + packages/jest-types/__typetests__/expect.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 53286977a83a..6b1d1b8560b0 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -74,6 +74,7 @@ interface AsymmetricMatchers { any(sample: unknown): AsymmetricMatcher; anything(): AsymmetricMatcher; arrayContaining(sample: Array): AsymmetricMatcher; + closeTo(sample: number, precision?: number): AsymmetricMatcher; objectContaining(sample: Record): AsymmetricMatcher; stringContaining(sample: string): AsymmetricMatcher; stringMatching(sample: string | RegExp): AsymmetricMatcher; diff --git a/packages/jest-types/__typetests__/expect.test.ts b/packages/jest-types/__typetests__/expect.test.ts index 3f6eae703433..37a6f9efb136 100644 --- a/packages/jest-types/__typetests__/expect.test.ts +++ b/packages/jest-types/__typetests__/expect.test.ts @@ -25,6 +25,17 @@ expectType(expect(['B']).toEqual(expect.not.arrayContaining(['A']))); expectError(expect(['A']).toEqual(expect.not.arrayContaining('A'))); expectError(expect(['A']).toEqual(expect.not.arrayContaining())); +expectType(expect(0.1 + 0.2).toEqual(expect.closeTo(0.3))); +expectType(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(expect(0.1 + 0.2).toEqual(expect.not.closeTo(0.3))); +expectType(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(expect({a: 1}).toEqual(expect.objectContaining({a: 1}))); expectError(expect({a: 1}).toEqual(expect.objectContaining(1))); expectError(expect({a: 1}).toEqual(expect.objectContaining())); From 0fb15f3b3eb3936ee1e17efe642e332326dc87c5 Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Sat, 5 Feb 2022 19:34:21 +0200 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad40bf59222f..38e17f9242ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[expect]` Add type definitions for asymmetric `closeTo` matcher ([#12304](https://github.com/facebook/jest/pull/12304)) + ### Chore & Maintenance ### Performance