diff --git a/packages/expect/src/jest-utils.ts b/packages/expect/src/jest-utils.ts index 7ca28b104c3b..8b0f9b337c9f 100644 --- a/packages/expect/src/jest-utils.ts +++ b/packages/expect/src/jest-utils.ts @@ -584,6 +584,8 @@ function isObjectWithKeys(a: any) { && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date) + && !(a instanceof Set) + && !(a instanceof Map) ) } diff --git a/packages/vitest/src/node/plugins/workspace.ts b/packages/vitest/src/node/plugins/workspace.ts index 4375874c29eb..dbfecb5e2049 100644 --- a/packages/vitest/src/node/plugins/workspace.ts +++ b/packages/vitest/src/node/plugins/workspace.ts @@ -112,6 +112,9 @@ export function WorkspaceVitestPlugin( if (testConfig.experimental?.nodeLoader == null && project.vitest.config.experimental?.nodeLoader != null) { vitestConfig.experimental.nodeLoader = project.vitest.config.experimental.nodeLoader } + if (testConfig.experimental?.importDurations == null && project.vitest.config.experimental?.importDurations != null) { + vitestConfig.experimental.importDurations = project.vitest.config.experimental.importDurations + } return { base: '/', diff --git a/test/config/test/cli-config.test.ts b/test/config/test/cli-config.test.ts index 0269f0954479..23064dcca089 100644 --- a/test/config/test/cli-config.test.ts +++ b/test/config/test/cli-config.test.ts @@ -31,6 +31,11 @@ it('correctly inherit from the cli', async () => { testNamePattern: 'math', passWithNoTests: true, bail: 100, + experimental: { + importDurations: { + print: true, + }, + }, }, }) const project = ctx!.projects[0] @@ -48,6 +53,12 @@ it('correctly inherit from the cli', async () => { retry: 6, passWithNoTests: true, bail: 100, + experimental: expect.objectContaining({ + importDurations: { + print: true, + limit: 10, + }, + }), }) expect(config.testNamePattern?.test('math')).toBe(true) }) diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index cee708112ac4..903ec9e8f9e1 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -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(`