Concepts

mock.fn()

Try the free JavaScript compiler

Creates a tracked mock function in Node’s test API. Its mock context records call metadata; prefer a scoped test context when available.

Formal Syntax & Structure

javascript syntaxjavascript
mock.fn([original[, implementation]][, options])

Return Value

function

Tracked function.

Working Example

Example Snippetjavascript
(async () => {const {mock}=require("node:test");const send=mock.fn(x=>x.toUpperCase());const result=send("ok");console.log(result,send.mock.callCount(),send.mock.calls[0].arguments[0]);})()
JavaScript Reference