From 1dbdd67ca4792b91df77ed2c586b079f67335ff3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 2 Nov 2020 12:45:14 +0100 Subject: [PATCH] Revert "fix(expect): `objectContaining` should recurse into sub-objects (#10508)" (#10766) --- CHANGELOG.md | 2 +- packages/babel-jest/src/__tests__/index.ts | 11 ++++++++++- .../expect/src/__tests__/asymmetricMatchers.test.ts | 11 ++++++++--- packages/expect/src/asymmetricMatchers.ts | 8 +------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c652a32acd75..1e0e2ed1dc93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - `[babel-plugin-jest-hoist]` Preserve order of hoisted mock nodes within containing block ([#10536](https://github.com/facebook/jest/pull/10536)) - `[babel-plugin-jest-hoist]` Hoist pure constants to support experimental JSX transform in hoisted mocks ([#10723](https://github.com/facebook/jest/pull/10723)) - `[babel-preset-jest]` Update `babel-preset-current-node-syntax` to support top level await ([#10747](https://github.com/facebook/jest/pull/10747)) -- `[expect]` Stop modifying the sample in `expect.objectContaining()` ([#10711](https://github.com/facebook/jest/pull/10711)) +- `[expect]` Revert "Fix `objectContaining` to work recursively into sub-objects ([#10508](https://github.com/facebook/jest/pull/10508))" ([#10766](https://github.com/facebook/jest/pull/10766)) - `[jest-circus, jest-jasmine2]` fix: don't assume `stack` is always a string ([#10697](https://github.com/facebook/jest/pull/10697)) - `[jest-config]` Fix bug introduced in watch mode by PR [#10678](https://github.com/facebook/jest/pull/10678/files#r511037803) ([#10692](https://github.com/facebook/jest/pull/10692)) - `[jest-config]` Throw correct error for missing preset modules ([#10737](https://github.com/facebook/jest/pull/10737)) diff --git a/packages/babel-jest/src/__tests__/index.ts b/packages/babel-jest/src/__tests__/index.ts index 99fd909be5b4..4ee2960bd65e 100644 --- a/packages/babel-jest/src/__tests__/index.ts +++ b/packages/babel-jest/src/__tests__/index.ts @@ -93,7 +93,14 @@ describe('caller option correctly merges from defaults and options', () => { expect(loadPartialConfig).toHaveBeenCalledTimes(1); expect(loadPartialConfig).toHaveBeenCalledWith( - expect.objectContaining({caller: {name: 'babel-jest', ...output}}), + expect.objectContaining({ + caller: { + name: 'babel-jest', + ...output, + supportsExportNamespaceFrom: false, + supportsTopLevelAwait: false, + }, + }), ); }); }); @@ -110,7 +117,9 @@ test('can pass null to createTransformer', () => { caller: { name: 'babel-jest', supportsDynamicImport: false, + supportsExportNamespaceFrom: false, supportsStaticESM: false, + supportsTopLevelAwait: false, }, }), ); diff --git a/packages/expect/src/__tests__/asymmetricMatchers.test.ts b/packages/expect/src/__tests__/asymmetricMatchers.test.ts index 9da8f2cda5c6..6e1886b65409 100644 --- a/packages/expect/src/__tests__/asymmetricMatchers.test.ts +++ b/packages/expect/src/__tests__/asymmetricMatchers.test.ts @@ -162,12 +162,13 @@ test('ObjectContaining matches', () => { objectContaining({}).asymmetricMatch('jest'), objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foo', jest: 'jest'}), objectContaining({foo: undefined}).asymmetricMatch({foo: undefined}), - objectContaining({foo: {bar: [1]}}).asymmetricMatch({ - foo: {bar: [1], qux: []}, - }), objectContaining({first: objectContaining({second: {}})}).asymmetricMatch({ first: {second: {}}, }), + objectContaining({foo: Buffer.from('foo')}).asymmetricMatch({ + foo: Buffer.from('foo'), + jest: 'jest', + }), ].forEach(test => { jestExpect(test).toEqual(true); }); @@ -178,6 +179,10 @@ test('ObjectContaining does not match', () => { objectContaining({foo: 'foo'}).asymmetricMatch({bar: 'bar'}), objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foox'}), objectContaining({foo: undefined}).asymmetricMatch({}), + objectContaining({ + answer: 42, + foo: {bar: 'baz', foobar: 'qux'}, + }).asymmetricMatch({foo: {bar: 'baz'}}), ].forEach(test => { jestExpect(test).toEqual(false); }); diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index de604b205f13..b20f3052ca97 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -177,15 +177,9 @@ class ObjectContaining extends AsymmetricMatcher> { return true; } else { for (const property in this.sample) { - const expected = - typeof this.sample[property] === 'object' && - !(this.sample[property] instanceof AsymmetricMatcher) - ? objectContaining(this.sample[property] as Record) - : this.sample[property]; - if ( !hasProperty(other, property) || - !equals(expected, other[property]) + !equals(this.sample[property], other[property]) ) { return false; }