Skip to content

Accept mock.fn() without an original - #1417

Merged
ctate merged 3 commits into
mainfrom
ctate/accept-mock-fn-4b4c97
Oct 20, 2026
Merged

ctate merged 3 commits into
mainfrom
ctate/accept-mock-fn-4b4c97

Conversation

@ctate

@ctate ctate commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator
  • mock.fn() and t.mock.fn() without an original return undefined and record each call's arguments, matching Node 24.22.
  • Functions with only unknown/any parameters, or none, convert to (...args: unknown[]) => R slots, passing undefined for missing arguments.
  • New fixture mock-fn-default and corpus program 5816 match Node plain and with SCRIPTC_SAN=1.

node:test changes, matching Node 24.22:

- mock.fn() and t.mock.fn() without an original return undefined and
  record the arguments of each call, whatever the callers pass. The
  original and the initial implementation are a function that returns
  undefined, so restore() brings that function back.
- mock.fn<F>() with an explicit function type records F's parameters
  when F's return type is void or includes undefined. A return type
  without undefined, such as mock.fn<() => number>(), throws SC2020.

mock.fn()'s default type, (...args: any[]) => undefined, maps to the
checked-dynamic rest ABI used for program-declared (...args: unknown[])
functions: the calls log records the argument array, and the mock's
wrapper spreads it into the implementation.

A function whose fixed parameters are all unknown or any, or that has
none, now converts to a checked-dynamic rest signature without fixed
parameters, such as (...args: unknown[]) => void: each call passes the
arguments in order, undefined for the ones the caller left out. This is
how () => {} reaches mockImplementation and mockImplementationOnce, and
it applies to any such slot in TypeScript programs, which threw SC1090
before.

The mock-fn-default fixture and corpus program 5816 compare with Node,
plain and with SCRIPTC_SAN=1.
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 20, 2026 7:40am UTC

@ctate
ctate merged commit 35e5668 into main Oct 20, 2026
58 of 64 checks passed
@ctate
ctate deleted the ctate/accept-mock-fn-4b4c97 branch October 20, 2026 07:43

This branch was successfully deployed

1 active deployment
Preview — c8b22e34 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant