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 4 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))" ([#10760](https://github.com/facebook/jest/pull/10760))
- `[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
7 changes: 4 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 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