Skip to content

Commit

Permalink
fix: make Errors match with ordinary objects (fixes #5359) (#5611)
Browse files Browse the repository at this point in the history
* fix: make Errors match with ordinary objects (#5359)

* chore: updating CHANGELOG.md
  • Loading branch information
kpsroka authored and cpojer committed Feb 19, 2018
1 parent 0b88438 commit f5879c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

### Fixes

* `[enzyme]` Allow matching of Errors against plain objects
([#5611](https://github.com/facebook/jest/pull/5611))
* `[jest-cli]` Don't skip matchers for exact files
([#5582](https://github.com/facebook/jest/pull/5582))
* `[docs]` Update discord links
Expand Down
Expand Up @@ -3983,6 +3983,15 @@ Received:
<red>[1, 2]</>"
`;

exports[`toMatchObject() {pass: true} expect([Error: bar]).toMatchObject({"message": "bar"}) 1`] = `
"<dim>expect(</><red>received</><dim>).not.toMatchObject(</><green>expected</><dim>)</>

Expected value not to match object:
<green>{\\"message\\": \\"bar\\"}</>
Received:
<red>[Error: bar]</>"
`;

exports[`toMatchObject() {pass: true} expect([Error: foo]).toMatchObject([Error: foo]) 1`] = `
"<dim>expect(</><red>received</><dim>).not.toMatchObject(</><green>expected</><dim>)</>

Expand Down
4 changes: 4 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Expand Up @@ -28,6 +28,9 @@ describe('.rejects', () => {
await jestExpect(Promise.reject({a: 1, b: 2})).rejects.not.toMatchObject({
c: 1,
});
await jestExpect(
Promise.reject(new Error('rejectMessage')),
).rejects.toMatchObject({message: 'rejectMessage'});
await jestExpect(Promise.reject(new Error())).rejects.toThrow();
});

Expand Down Expand Up @@ -960,6 +963,7 @@ describe('toMatchObject()', () => {
[{a: undefined}, {a: undefined}],
[[], []],
[new Error('foo'), new Error('foo')],
[new Error('bar'), {message: 'bar'}],
].forEach(([n1, n2]) => {
it(`{pass: true} expect(${stringify(n1)}).toMatchObject(${stringify(
n2,
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/utils.js
Expand Up @@ -174,7 +174,7 @@ const isObjectWithKeys = a =>
!(a instanceof Date);

export const subsetEquality = (object: Object, subset: Object) => {
if (!isObjectWithKeys(object) || !isObjectWithKeys(subset)) {
if (!isObjectWithKeys(subset)) {
return undefined;
}

Expand Down

0 comments on commit f5879c0

Please sign in to comment.