From ecb583630d412d6dcb8c75624ad42748adb6d7c4 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 5 Mar 2018 00:59:46 +0100 Subject: [PATCH] docs: Expand changelog entry for #5367 (#5719) --- CHANGELOG.md | 4 ++-- .../src/__tests__/__snapshots__/matchers.test.js.snap | 9 +++++++++ packages/expect/src/__tests__/matchers.test.js | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a65b1f8de49d..7cc689b3f702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -215,8 +215,8 @@ malformed source-map. ([#5405](https://github.com/facebook/jest/pull/5405)). * `[jest]` Add `import-local` to `jest` package. ([#5353](https://github.com/facebook/jest/pull/5353)) -* `[expect]` Support class instances in `.toHaveProperty()` matcher. - ([#5367](https://github.com/facebook/jest/pull/5367)) +* `[expect]` Support class instances in `.toHaveProperty()` and `.toMatchObject` + matcher. ([#5367](https://github.com/facebook/jest/pull/5367)) * `[jest-cli]` Fix npm update command for snapshot summary. ([#5376](https://github.com/facebook/jest/pull/5376), [5389](https://github.com/facebook/jest/pull/5389/)) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index f9c34d1a4a3d..1a759e202655 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -3840,6 +3840,15 @@ Received: {\\"a\\": undefined}" `; +exports[`toMatchObject() {pass: true} expect({}).toMatchObject({"a": undefined, "b": "b"}) 1`] = ` +"expect(received).not.toMatchObject(expected) + +Expected value not to match object: + {\\"a\\": undefined, \\"b\\": \\"b\\"} +Received: + {}" +`; + exports[`toMatchObject() {pass: true} expect(2015-11-30T00:00:00.000Z).toMatchObject(2015-11-30T00:00:00.000Z) 1`] = ` "expect(received).not.toMatchObject(expected) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index da839ca74675..bcd836e78097 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -953,6 +953,15 @@ describe('.toHaveProperty()', () => { }); describe('toMatchObject()', () => { + class Foo { + get a() { + return undefined; + } + get b() { + return 'b'; + } + } + [ [{a: 'b', c: 'd'}, {a: 'b'}], [{a: 'b', c: 'd'}, {a: 'b', c: 'd'}], @@ -974,6 +983,7 @@ describe('toMatchObject()', () => { [[], []], [new Error('foo'), new Error('foo')], [new Error('bar'), {message: 'bar'}], + [new Foo(), {a: undefined, b: 'b'}], ].forEach(([n1, n2]) => { it(`{pass: true} expect(${stringify(n1)}).toMatchObject(${stringify( n2,