Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/expect/src/jest-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ function isObjectWithKeys(a: any) {
&& !(a instanceof Error)
&& !Array.isArray(a)
&& !(a instanceof Date)
&& !(a instanceof Set)
&& !(a instanceof Map)
)
}

Expand Down
23 changes: 23 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,29 @@ function getError(f: () => unknown) {
return expect.unreachable()
}

it('toMatchObject', () => {
expect(() => expect(null).toMatchObject(new Set()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected null to match object Set{}]`)
expect(() => expect(undefined).toMatchObject(new Set()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected undefined to match object Set{}]`)
expect(() => expect(1234).toMatchObject(new Set()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected 1234 to match object Set{}]`)
expect(() => expect('hello').toMatchObject(new Set()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected 'hello' to match object Set{}]`)
expect(() => expect({}).toMatchObject(new Set()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected {} to match object Set{}]`)
expect(() => expect({}).toMatchObject(new Map()))
.toThrowErrorMatchingInlineSnapshot(`[AssertionError: expected {} to match object Map{}]`)

// subset equality works inside Set/Map
expect(new Set([{ x: 1 }])).toMatchObject(new Set([{}]))
expect(new Map([[1, { a: 1 }]])).toMatchObject(new Map([[1, {}]]))

// Set/Map matches against empty object shape
expect(new Set()).toMatchObject({})
expect(new Map()).toMatchObject({})
})

it('toMatchObject error diff', () => {
// single property on root (3 total properties, 1 expected)
expect(getError(() => expect({ a: 1, b: 2, c: 3 }).toMatchObject({ c: 4 }))).toMatchInlineSnapshot(`
Expand Down
Loading