vitest-dev/vitest · error · AssertionError

${msg} (${stripped} matching ${stripped === 1 ? 'property' :

Error message

${msg}
(${stripped} matching ${stripped === 1 ? 'property' : 'properties'} omitted from actual)

What it means

Failure message emitted by the toMatchObject matcher when, during subset equality comparison, some properties that were also present on the actual object were 'stripped' (omitted) from the diff output because they matched. The (N matching property|properties omitted from actual) suffix tells the developer how many keys were elided from the visible diff so the message stays readable.

Source

Thrown at packages/expect/src/jest-expect.ts:217

      expected,
      customTesters,
    )
    if ((pass && isNot) || (!pass && !isNot)) {
      const msg = utils.getMessage(this, [
        pass,
        'expected #{this} to match object #{exp}',
        'expected #{this} to not match object #{exp}',
        expected,
        actualSubset,
        false,
      ])
      const message
        = stripped === 0
          ? msg
          : `${msg}\n(${stripped} matching ${
            stripped === 1 ? 'property' : 'properties'
          } omitted from actual)`
      throw new AssertionError(message, {
        showDiff: true,
        expected,
        actual: actualSubset,
      })
    }
  })
  def('toMatch', function (expected: string | RegExp) {
    const actual = this._obj as string
    if (typeof actual !== 'string') {
      throw new TypeError(
        `.toMatch() expects to receive a string, but got ${typeof actual}`,
      )
    }

    return this.assert(
      typeof expected === 'string'
        ? actual.includes(expected)
        : actual.match(expected),

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Inspect the full diff: the matched properties are intentionally hidden; use expect(actual).toEqual(expected) if you want a complete comparison.
  2. If you expected the omitted properties to differ, verify the actual value actually differs — subsetEquality may have treated them as equal due to deep equality semantics.
  3. Narrow the expected object to only the fields under test to reduce noise.
Defensive patterns

Strategy: validation

Validate before calling

const matchedKeys = Object.keys(expected).filter(k => k in actual);
// 'stripped' will equal matchedKeys.length; pass it to a custom logger if needed

Prevention

When it happens

Trigger: expect(actual).toMatchObject(expected) (or the .not form) fails the subsetEquality check AND stripped > 0. 'stripped' counts keys that exist on actual but were matched-and-removed by the subsetEquality tester before diffing. Fires whenever the assertion does not pass and at least one actual-side key matched the expected subset.

Common situations: Large actual objects compared against smaller expected subsets — common when matching a partial response payload from an API or DB row. The omission note surprises developers who think properties are missing when they are actually just hidden for brevity.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/04f53955892e307b.json. Report an issue: GitHub.