From 3a9e331ab73793e7a4e0c039a0a9243a94d21dc1 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sat, 2 Apr 2022 20:50:06 +0300 Subject: [PATCH 01/13] Fix pretty print for closeTo matcher --- .../src/__tests__/AsymmetricMatcher.test.ts | 10 ++++++++++ .../pretty-format/src/plugins/AsymmetricMatcher.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index dd0495fb17d4..eec01947cf12 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -131,6 +131,16 @@ test('stringNotMatching(string)', () => { expect(result).toEqual('StringNotMatching /jest/'); }); +test('closeTo()', () => { + const result = prettyFormat(expect.closeTo(1.2345, 4), options); + expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); +}); + +test('notCloseTo()', () => { + const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); + expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); +}); + test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 7457cdd8973b..6ff342f3beb7 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -6,6 +6,7 @@ */ import {printListItems, printObjectProperties} from '../collections'; +import {pluralize} from 'jest-util'; import type {Config, NewPlugin, Printer, Refs} from '../types'; const asymmetricMatcher = @@ -80,6 +81,19 @@ export const serialize: NewPlugin['serialize'] = ( ); } + if ( + stringedValue === 'NumberCloseTo' || + stringedValue === 'NumberNotCloseTo' + ) { + return ( + stringedValue + + SPACE + + printer(val.sample, config, indentation, depth, refs) + + SPACE + + `(${pluralize('digit', val.precision)})` + ); + } + return val.toAsymmetricMatcher(); }; From a2c879dddf77816767b4cd18b944fe8dc6df9ea2 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sat, 2 Apr 2022 21:03:22 +0300 Subject: [PATCH 02/13] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bee7bad05887..cd2fc1f3175a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ - `[jest-reporters]` Notifications generated by the `--notify` flag are no longer persistent in GNOME Shell. ([#11733](https://github.com/facebook/jest/pull/11733)) - `[@jest-reporters]` Move missing icon file which is needed for `NotifyReporter` class. ([#12593](https://github.com/facebook/jest/pull/12593)) - `[jest-worker]` Fix `Farm` execution results memory leak ([#12497](https://github.com/facebook/jest/pull/12497)) +- `[pretty-format]` Fix print for the `closeTo` matcher ([#12626](https://github.com/facebook/jest/pull/12626)) ### Chore & Maintenance From e9fea882a296987d97ebadecbafd8c5a07ded5f1 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sun, 3 Apr 2022 14:34:25 +0300 Subject: [PATCH 03/13] Add more tests for closeTo print --- .../src/__tests__/AsymmetricMatcher.test.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index eec01947cf12..8089ca00f242 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -131,16 +131,37 @@ test('stringNotMatching(string)', () => { expect(result).toEqual('StringNotMatching /jest/'); }); -test('closeTo()', () => { +test('closeTo(number, precision)', () => { const result = prettyFormat(expect.closeTo(1.2345, 4), options); expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); }); -test('notCloseTo()', () => { +test('notCloseTo(number, precision)', () => { const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); }); +test('closeTo(number)', () => { + const result = prettyFormat(expect.closeTo(1.2345), options); + expect(result).toEqual(`NumberCloseTo 1.2345 (2 digits)`); +}); + +test('closeTo(Infinity)', () => { + const result = prettyFormat(expect.closeTo(-Infinity), options); + expect(result).toEqual(`NumberCloseTo -Infinity (2 digits)`); +}); + +test('closeTo(scientific number)', () => { + const result = prettyFormat(expect.closeTo(1.56e-3, 4), options); + expect(result).toEqual(`NumberCloseTo 0.00156 (4 digits)`); +}); + +test('closeTo(very small scientific number)', () => { + const result = prettyFormat(expect.closeTo(1.56e-10, 4), options); + expect(result).toEqual(`NumberCloseTo 1.56e-10 (4 digits)`); +}); + + test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { From bf9f448ca809d08d28f4a0a7cbf820d096a56097 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sun, 3 Apr 2022 14:35:49 +0300 Subject: [PATCH 04/13] Fix lint issues --- .../src/__tests__/AsymmetricMatcher.test.ts | 13 ++++++------- .../pretty-format/src/plugins/AsymmetricMatcher.ts | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index 8089ca00f242..cbb25156bf16 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -133,35 +133,34 @@ test('stringNotMatching(string)', () => { test('closeTo(number, precision)', () => { const result = prettyFormat(expect.closeTo(1.2345, 4), options); - expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); + expect(result).toEqual('NumberCloseTo 1.2345 (4 digits)'); }); test('notCloseTo(number, precision)', () => { const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); - expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); + expect(result).toEqual('NumberNotCloseTo 1.2345 (1 digit)'); }); test('closeTo(number)', () => { const result = prettyFormat(expect.closeTo(1.2345), options); - expect(result).toEqual(`NumberCloseTo 1.2345 (2 digits)`); + expect(result).toEqual('NumberCloseTo 1.2345 (2 digits)'); }); test('closeTo(Infinity)', () => { const result = prettyFormat(expect.closeTo(-Infinity), options); - expect(result).toEqual(`NumberCloseTo -Infinity (2 digits)`); + expect(result).toEqual('NumberCloseTo -Infinity (2 digits)'); }); test('closeTo(scientific number)', () => { const result = prettyFormat(expect.closeTo(1.56e-3, 4), options); - expect(result).toEqual(`NumberCloseTo 0.00156 (4 digits)`); + expect(result).toEqual('NumberCloseTo 0.00156 (4 digits)'); }); test('closeTo(very small scientific number)', () => { const result = prettyFormat(expect.closeTo(1.56e-10, 4), options); - expect(result).toEqual(`NumberCloseTo 1.56e-10 (4 digits)`); + expect(result).toEqual('NumberCloseTo 1.56e-10 (4 digits)'); }); - test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 6ff342f3beb7..11e77a3c7223 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {printListItems, printObjectProperties} from '../collections'; import {pluralize} from 'jest-util'; +import {printListItems, printObjectProperties} from '../collections'; import type {Config, NewPlugin, Printer, Refs} from '../types'; const asymmetricMatcher = @@ -85,13 +85,12 @@ export const serialize: NewPlugin['serialize'] = ( stringedValue === 'NumberCloseTo' || stringedValue === 'NumberNotCloseTo' ) { - return ( + return `${ stringedValue + SPACE + printer(val.sample, config, indentation, depth, refs) + - SPACE + - `(${pluralize('digit', val.precision)})` - ); + SPACE + }(${pluralize('digit', val.precision)})`; } return val.toAsymmetricMatcher(); From 4520bd99443f82726fa085cdb5f80a3457dcf9a1 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sat, 2 Apr 2022 20:50:06 +0300 Subject: [PATCH 05/13] Fix pretty print for closeTo matcher --- .../src/__tests__/AsymmetricMatcher.test.ts | 10 ++++++++++ .../pretty-format/src/plugins/AsymmetricMatcher.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index dd0495fb17d4..eec01947cf12 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -131,6 +131,16 @@ test('stringNotMatching(string)', () => { expect(result).toEqual('StringNotMatching /jest/'); }); +test('closeTo()', () => { + const result = prettyFormat(expect.closeTo(1.2345, 4), options); + expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); +}); + +test('notCloseTo()', () => { + const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); + expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); +}); + test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 7457cdd8973b..6ff342f3beb7 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -6,6 +6,7 @@ */ import {printListItems, printObjectProperties} from '../collections'; +import {pluralize} from 'jest-util'; import type {Config, NewPlugin, Printer, Refs} from '../types'; const asymmetricMatcher = @@ -80,6 +81,19 @@ export const serialize: NewPlugin['serialize'] = ( ); } + if ( + stringedValue === 'NumberCloseTo' || + stringedValue === 'NumberNotCloseTo' + ) { + return ( + stringedValue + + SPACE + + printer(val.sample, config, indentation, depth, refs) + + SPACE + + `(${pluralize('digit', val.precision)})` + ); + } + return val.toAsymmetricMatcher(); }; From 59ff60d0180b9b8230881b53e37afff153373fda Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sat, 2 Apr 2022 21:03:22 +0300 Subject: [PATCH 06/13] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f48c8855293..c4b5b435609e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ - `[@jest/reporters]` Move missing icon file which is needed for `NotifyReporter` class. ([#12593](https://github.com/facebook/jest/pull/12593)) - `[jest-resolver]` Call custom resolver with core node.js modules ([#12654](https://github.com/facebook/jest/pull/12654)) - `[jest-worker]` Fix `Farm` execution results memory leak ([#12497](https://github.com/facebook/jest/pull/12497)) +- `[pretty-format]` Fix print for the `closeTo` matcher ([#12626](https://github.com/facebook/jest/pull/12626)) ### Chore & Maintenance From 606ae89a568cdbcda8750467565d905d620553fb Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sun, 3 Apr 2022 14:34:25 +0300 Subject: [PATCH 07/13] Add more tests for closeTo print --- .../src/__tests__/AsymmetricMatcher.test.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index eec01947cf12..8089ca00f242 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -131,16 +131,37 @@ test('stringNotMatching(string)', () => { expect(result).toEqual('StringNotMatching /jest/'); }); -test('closeTo()', () => { +test('closeTo(number, precision)', () => { const result = prettyFormat(expect.closeTo(1.2345, 4), options); expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); }); -test('notCloseTo()', () => { +test('notCloseTo(number, precision)', () => { const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); }); +test('closeTo(number)', () => { + const result = prettyFormat(expect.closeTo(1.2345), options); + expect(result).toEqual(`NumberCloseTo 1.2345 (2 digits)`); +}); + +test('closeTo(Infinity)', () => { + const result = prettyFormat(expect.closeTo(-Infinity), options); + expect(result).toEqual(`NumberCloseTo -Infinity (2 digits)`); +}); + +test('closeTo(scientific number)', () => { + const result = prettyFormat(expect.closeTo(1.56e-3, 4), options); + expect(result).toEqual(`NumberCloseTo 0.00156 (4 digits)`); +}); + +test('closeTo(very small scientific number)', () => { + const result = prettyFormat(expect.closeTo(1.56e-10, 4), options); + expect(result).toEqual(`NumberCloseTo 1.56e-10 (4 digits)`); +}); + + test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { From 446e30208118a693a66b4101c535a2552657fdc7 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sun, 3 Apr 2022 14:35:49 +0300 Subject: [PATCH 08/13] Fix lint issues --- .../src/__tests__/AsymmetricMatcher.test.ts | 13 ++++++------- .../pretty-format/src/plugins/AsymmetricMatcher.ts | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index 8089ca00f242..cbb25156bf16 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -133,35 +133,34 @@ test('stringNotMatching(string)', () => { test('closeTo(number, precision)', () => { const result = prettyFormat(expect.closeTo(1.2345, 4), options); - expect(result).toEqual(`NumberCloseTo 1.2345 (4 digits)`); + expect(result).toEqual('NumberCloseTo 1.2345 (4 digits)'); }); test('notCloseTo(number, precision)', () => { const result = prettyFormat(expect.not.closeTo(1.2345, 1), options); - expect(result).toEqual(`NumberNotCloseTo 1.2345 (1 digit)`); + expect(result).toEqual('NumberNotCloseTo 1.2345 (1 digit)'); }); test('closeTo(number)', () => { const result = prettyFormat(expect.closeTo(1.2345), options); - expect(result).toEqual(`NumberCloseTo 1.2345 (2 digits)`); + expect(result).toEqual('NumberCloseTo 1.2345 (2 digits)'); }); test('closeTo(Infinity)', () => { const result = prettyFormat(expect.closeTo(-Infinity), options); - expect(result).toEqual(`NumberCloseTo -Infinity (2 digits)`); + expect(result).toEqual('NumberCloseTo -Infinity (2 digits)'); }); test('closeTo(scientific number)', () => { const result = prettyFormat(expect.closeTo(1.56e-3, 4), options); - expect(result).toEqual(`NumberCloseTo 0.00156 (4 digits)`); + expect(result).toEqual('NumberCloseTo 0.00156 (4 digits)'); }); test('closeTo(very small scientific number)', () => { const result = prettyFormat(expect.closeTo(1.56e-10, 4), options); - expect(result).toEqual(`NumberCloseTo 1.56e-10 (4 digits)`); + expect(result).toEqual('NumberCloseTo 1.56e-10 (4 digits)'); }); - test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 6ff342f3beb7..11e77a3c7223 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {printListItems, printObjectProperties} from '../collections'; import {pluralize} from 'jest-util'; +import {printListItems, printObjectProperties} from '../collections'; import type {Config, NewPlugin, Printer, Refs} from '../types'; const asymmetricMatcher = @@ -85,13 +85,12 @@ export const serialize: NewPlugin['serialize'] = ( stringedValue === 'NumberCloseTo' || stringedValue === 'NumberNotCloseTo' ) { - return ( + return `${ stringedValue + SPACE + printer(val.sample, config, indentation, depth, refs) + - SPACE + - `(${pluralize('digit', val.precision)})` - ); + SPACE + }(${pluralize('digit', val.precision)})`; } return val.toAsymmetricMatcher(); From 21ed485513b19ed59e5995b536ebe599f6510916 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Sun, 10 Apr 2022 20:14:32 +0300 Subject: [PATCH 09/13] Add clear error if toAsymmetricMatcher is not implemented --- packages/expect/src/asymmetricMatchers.ts | 9 +++++++++ .../src/plugins/AsymmetricMatcher.ts | 16 +++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index 58390fc11421..e9aff27f9a75 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -13,6 +13,7 @@ import { subsetEquality, } from '@jest/expect-utils'; import * as matcherUtils from 'jest-matcher-utils'; +import {pluralize} from 'jest-util'; import {getState} from './jestMatchersObject'; import type { AsymmetricMatcher as AsymmetricMatcherInterface, @@ -329,6 +330,14 @@ class CloseTo extends AsymmetricMatcher { override getExpectedType() { return 'number'; } + + override toAsymmetricMatcher(): string { + return [ + this.toString(), + this.sample, + `(${pluralize('digit', this.precision)})`, + ].join(' '); + } } export const any = (expectedObject: unknown): Any => new Any(expectedObject); diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 11e77a3c7223..718863c13f39 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {pluralize} from 'jest-util'; +import {isA} from '@jest/expect-utils'; import {printListItems, printObjectProperties} from '../collections'; import type {Config, NewPlugin, Printer, Refs} from '../types'; @@ -81,16 +81,10 @@ export const serialize: NewPlugin['serialize'] = ( ); } - if ( - stringedValue === 'NumberCloseTo' || - stringedValue === 'NumberNotCloseTo' - ) { - return `${ - stringedValue + - SPACE + - printer(val.sample, config, indentation, depth, refs) + - SPACE - }(${pluralize('digit', val.precision)})`; + if (!isA('Function', val.toAsymmetricMatcher)) { + throw new Error( + `Asymmetric matcher ${val.constructor.name} does not implement toAsymmetricMatcher()`, + ); } return val.toAsymmetricMatcher(); From f1bd068b4889b19bbf15e9857921e7500cc36bb5 Mon Sep 17 00:00:00 2001 From: Andrey Pozdnyakov Date: Thu, 14 Apr 2022 11:02:19 +0300 Subject: [PATCH 10/13] Add test for .toAsymmetricMatcher is undefined --- .../src/__tests__/AsymmetricMatcher.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index cbb25156bf16..15a08d26da53 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -6,6 +6,7 @@ */ import prettyFormat, {plugins} from '../'; +import {AsymmetricMatcher as AbstractAsymmetricMatcher} from '../../../expect/src/asymmetricMatchers'; import type {OptionsReceived} from '../types'; const {AsymmetricMatcher} = plugins; @@ -161,6 +162,12 @@ test('closeTo(very small scientific number)', () => { expect(result).toEqual('NumberCloseTo 1.56e-10 (4 digits)'); }); +test('correctly handles inability to pretty-print matcher', () => { + expect(() => prettyFormat(new DummyMatcher(1), options)).toThrow( + 'Asymmetric matcher DummyMatcher does not implement toAsymmetricMatcher()', + ); +}); + test('supports multiple nested asymmetric matchers', () => { const result = prettyFormat( { @@ -341,3 +348,21 @@ test('min option', () => { '{"test": {"nested": ObjectContaining {"a": ArrayContaining [1], "b": Anything, "c": Any, "d": StringContaining "jest", "e": StringMatching /jest/, "f": ObjectContaining {"test": "case"}}}}', ); }); + +class DummyMatcher extends AbstractAsymmetricMatcher { + constructor(sample: number) { + super(sample); + } + + asymmetricMatch(other: number) { + return this.sample === other; + } + + toString() { + return 'DummyMatcher'; + } + + override getExpectedType() { + return 'number'; + } +} From 033ce25e1f733f6967000b21c31cf79b90d47ed2 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 14 Apr 2022 12:20:27 +0200 Subject: [PATCH 11/13] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 245804a70a7f..dfa05c42e017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ - `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346)) - `[expect]` Throw useful error if `expect.extend` is called with invalid matchers ([#12488](https://github.com/facebook/jest/pull/12488)) - `[expect]` Fix `iterableEquality` ignores other properties ([#8359](https://github.com/facebook/jest/pull/8359)) +- `[expect]` Fix print for the `closeTo` matcher ([#12626](https://github.com/facebook/jest/pull/12626)) - `[jest-circus, @jest/types]` Disallow undefined value in `TestContext` type ([#12507](https://github.com/facebook/jest/pull/12507)) - `[jest-config]` Correctly detect CI environment and update snapshots accordingly ([#12378](https://github.com/facebook/jest/pull/12378)) - `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397)) @@ -81,7 +82,6 @@ - `[@jest/reporters]` Move missing icon file which is needed for `NotifyReporter` class. ([#12593](https://github.com/facebook/jest/pull/12593)) - `[jest-resolver]` Call custom resolver with core node.js modules ([#12654](https://github.com/facebook/jest/pull/12654)) - `[jest-worker]` Fix `Farm` execution results memory leak ([#12497](https://github.com/facebook/jest/pull/12497)) -- `[pretty-format]` Fix print for the `closeTo` matcher ([#12626](https://github.com/facebook/jest/pull/12626)) ### Chore & Maintenance From b5c95d1f24e7a50bba52fe4adcea7ff4820c88c8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 14 Apr 2022 12:35:10 +0200 Subject: [PATCH 12/13] drop dep, export assymetrircmatcher --- packages/expect/src/index.ts | 1 + packages/pretty-format/package.json | 1 + packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts | 2 +- packages/pretty-format/src/plugins/AsymmetricMatcher.ts | 3 +-- packages/pretty-format/tsconfig.json | 1 + yarn.lock | 1 + 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index ee6179aa8402..4511b9e0b8bb 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -49,6 +49,7 @@ import type { ThrowingMatcherFn, } from './types'; +export {AsymmetricMatcher} from './asymmetricMatchers'; export type { AsymmetricMatchers, BaseExpect, diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index 689422ef07bc..690af3ce4e36 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -29,6 +29,7 @@ "@types/react": "*", "@types/react-is": "^17.0.0", "@types/react-test-renderer": "*", + "expect": "^28.0.0-alpha.8", "immutable": "^4.0.0", "jest-util": "^28.0.0-alpha.8", "react": "*", diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index 15a08d26da53..42da89bd9b25 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import {AsymmetricMatcher as AbstractAsymmetricMatcher} from 'expect'; import prettyFormat, {plugins} from '../'; -import {AsymmetricMatcher as AbstractAsymmetricMatcher} from '../../../expect/src/asymmetricMatchers'; import type {OptionsReceived} from '../types'; const {AsymmetricMatcher} = plugins; diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts index 718863c13f39..331b64e1dbb5 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.ts +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import {isA} from '@jest/expect-utils'; import {printListItems, printObjectProperties} from '../collections'; import type {Config, NewPlugin, Printer, Refs} from '../types'; @@ -81,7 +80,7 @@ export const serialize: NewPlugin['serialize'] = ( ); } - if (!isA('Function', val.toAsymmetricMatcher)) { + if (typeof val.toAsymmetricMatcher !== 'function') { throw new Error( `Asymmetric matcher ${val.constructor.name} does not implement toAsymmetricMatcher()`, ); diff --git a/packages/pretty-format/tsconfig.json b/packages/pretty-format/tsconfig.json index b91ffb6b1f33..6f91b2984094 100644 --- a/packages/pretty-format/tsconfig.json +++ b/packages/pretty-format/tsconfig.json @@ -6,5 +6,6 @@ }, "include": ["./src/**/*"], "exclude": ["./**/__tests__/**/*"], + // no `expect`, only used in tests "references": [{"path": "../jest-schemas"}, {"path": "../jest-util"}] } diff --git a/yarn.lock b/yarn.lock index f8d2457c09c3..2455bf6708ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17974,6 +17974,7 @@ __metadata: "@types/react-test-renderer": "*" ansi-regex: ^5.0.1 ansi-styles: ^5.0.0 + expect: ^28.0.0-alpha.8 immutable: ^4.0.0 jest-util: ^28.0.0-alpha.8 react: "*" From a428795f5cb7e1a8ff1571726b8cdc69b56369ac Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 14 Apr 2022 12:38:03 +0200 Subject: [PATCH 13/13] allow dev dep in check --- scripts/buildTs.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/buildTs.mjs b/scripts/buildTs.mjs index 6ab57279aced..c8fb4267c076 100644 --- a/scripts/buildTs.mjs +++ b/scripts/buildTs.mjs @@ -62,6 +62,13 @@ import {getPackages} from './buildUtils.mjs'; } } + // dev dep + if (pkg.name === 'pretty-format') { + if (dep === 'expect') { + return false; + } + } + return true; }) .map(dep => @@ -84,7 +91,7 @@ import {getPackages} from './buildUtils.mjs'; assert.deepStrictEqual( references, jestDependenciesOfPackage, - `Expected declared references to match dependencies in packages ${ + `Expected declared references to match dependencies in package ${ pkg.name }. Got:\n\n${references.join( '\n',