Skip to content

Commit 1dbdd67

Browse files
authored
Revert "fix(expect): objectContaining should recurse into sub-objects (#10508)" (#10766)
1 parent 038d8be commit 1dbdd67

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- `[babel-plugin-jest-hoist]` Preserve order of hoisted mock nodes within containing block ([#10536](https://github.com/facebook/jest/pull/10536))
1010
- `[babel-plugin-jest-hoist]` Hoist pure constants to support experimental JSX transform in hoisted mocks ([#10723](https://github.com/facebook/jest/pull/10723))
1111
- `[babel-preset-jest]` Update `babel-preset-current-node-syntax` to support top level await ([#10747](https://github.com/facebook/jest/pull/10747))
12-
- `[expect]` Stop modifying the sample in `expect.objectContaining()` ([#10711](https://github.com/facebook/jest/pull/10711))
12+
- `[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))
1313
- `[jest-circus, jest-jasmine2]` fix: don't assume `stack` is always a string ([#10697](https://github.com/facebook/jest/pull/10697))
1414
- `[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))
1515
- `[jest-config]` Throw correct error for missing preset modules ([#10737](https://github.com/facebook/jest/pull/10737))

packages/babel-jest/src/__tests__/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ describe('caller option correctly merges from defaults and options', () => {
9393

9494
expect(loadPartialConfig).toHaveBeenCalledTimes(1);
9595
expect(loadPartialConfig).toHaveBeenCalledWith(
96-
expect.objectContaining({caller: {name: 'babel-jest', ...output}}),
96+
expect.objectContaining({
97+
caller: {
98+
name: 'babel-jest',
99+
...output,
100+
supportsExportNamespaceFrom: false,
101+
supportsTopLevelAwait: false,
102+
},
103+
}),
97104
);
98105
});
99106
});
@@ -110,7 +117,9 @@ test('can pass null to createTransformer', () => {
110117
caller: {
111118
name: 'babel-jest',
112119
supportsDynamicImport: false,
120+
supportsExportNamespaceFrom: false,
113121
supportsStaticESM: false,
122+
supportsTopLevelAwait: false,
114123
},
115124
}),
116125
);

packages/expect/src/__tests__/asymmetricMatchers.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ test('ObjectContaining matches', () => {
162162
objectContaining({}).asymmetricMatch('jest'),
163163
objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foo', jest: 'jest'}),
164164
objectContaining({foo: undefined}).asymmetricMatch({foo: undefined}),
165-
objectContaining({foo: {bar: [1]}}).asymmetricMatch({
166-
foo: {bar: [1], qux: []},
167-
}),
168165
objectContaining({first: objectContaining({second: {}})}).asymmetricMatch({
169166
first: {second: {}},
170167
}),
168+
objectContaining({foo: Buffer.from('foo')}).asymmetricMatch({
169+
foo: Buffer.from('foo'),
170+
jest: 'jest',
171+
}),
171172
].forEach(test => {
172173
jestExpect(test).toEqual(true);
173174
});
@@ -178,6 +179,10 @@ test('ObjectContaining does not match', () => {
178179
objectContaining({foo: 'foo'}).asymmetricMatch({bar: 'bar'}),
179180
objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foox'}),
180181
objectContaining({foo: undefined}).asymmetricMatch({}),
182+
objectContaining({
183+
answer: 42,
184+
foo: {bar: 'baz', foobar: 'qux'},
185+
}).asymmetricMatch({foo: {bar: 'baz'}}),
181186
].forEach(test => {
182187
jestExpect(test).toEqual(false);
183188
});

packages/expect/src/asymmetricMatchers.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,9 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
177177
return true;
178178
} else {
179179
for (const property in this.sample) {
180-
const expected =
181-
typeof this.sample[property] === 'object' &&
182-
!(this.sample[property] instanceof AsymmetricMatcher)
183-
? objectContaining(this.sample[property] as Record<string, unknown>)
184-
: this.sample[property];
185-
186180
if (
187181
!hasProperty(other, property) ||
188-
!equals(expected, other[property])
182+
!equals(this.sample[property], other[property])
189183
) {
190184
return false;
191185
}

0 commit comments

Comments
 (0)