Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(expect): objectContaining should recurse into sub-objects (#10508)" #10766

Merged
merged 7 commits into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never released, so I just removed it. Keeping the test, tho 👍

- `[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))
Expand Down
11 changes: 10 additions & 1 deletion packages/babel-jest/src/__tests__/index.ts
Expand Up @@ -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({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good example of the use case of expect.objectContaining current behavior - I only care about a subset of the properties, but I care about all of their properties

should probably add a test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added here: cda33c9 (#10766)

caller: {
name: 'babel-jest',
...output,
supportsExportNamespaceFrom: false,
supportsTopLevelAwait: false,
},
}),
);
});
});
Expand All @@ -110,7 +117,9 @@ test('can pass null to createTransformer', () => {
caller: {
name: 'babel-jest',
supportsDynamicImport: false,
supportsExportNamespaceFrom: false,
supportsStaticESM: false,
supportsTopLevelAwait: false,
},
}),
);
Expand Down
11 changes: 8 additions & 3 deletions packages/expect/src/__tests__/asymmetricMatchers.test.ts
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
8 changes: 1 addition & 7 deletions packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -177,15 +177,9 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
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<string, unknown>)
: this.sample[property];

if (
!hasProperty(other, property) ||
!equals(expected, other[property])
!equals(this.sample[property], other[property])
) {
return false;
}
Expand Down