跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

test

最后更新 查看 MarkdownAgent 设置

MockTracker

Node.js 中的 MockTracker API 提供在测试环境中跟踪和管理 mock 对象的方法。

import { mock } from 'node:test';

const fn = mock.fn();
fn(1,2,3);  // does nothing... but

console.log(fn.mock.callCount());  // Records how many times it was called
console.log(fn.mock.calls[0].arguments);  // Records the arguments that were passed each call

完整的 MockTracker API 文档见 Node.js MockTracker 文档 ↗。

Workers 的 MockTracker 实现目前不包含 Node.js mock timers API ↗ 的实现。

这篇文档对您有帮助吗?