Skip to content

Testing expect(null).toMatchObject(...) against a Map or Set should fail #9522

@eemeli

Description

@eemeli

Describe the bug

The following tests should fail, but do not:

import { expect, test } from 'vitest'

test.fails('null does not match map', () => {
  expect(null).toMatchObject(new Map([[1, 2]]));
})

test.fails('null does not match set', () => {
  expect(null).toMatchObject(new Set([[1]]));
})

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-y9khowyu?file=test%2Fbasic.test.ts

System Info

System:
    OS: macOS 15.7.3
    CPU: (14) arm64 Apple M4 Pro
    Memory: 6.79 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 25.2.1 - /opt/homebrew/bin/node
    npm: 11.7.0 - /opt/homebrew/bin/npm
  Browsers:
    Firefox: 146.0
    Firefox Nightly: 149.0a1
    Safari: 18.6
  npmPackages:
    @vitejs/plugin-react: ^5.1.1 => 5.1.1
    @vitest/coverage-v8: ^4.0.14 => 4.0.14
    vitest: ^4.0.9 => 4.0.14

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-to-be-discussedEnhancement under consideration (priority)p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    Status

    P2 - 3

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions