test
To enable built-in Node.js APIs and polyfills, add the nodejs_compat compatibility flag to your Wrangler configuration file. This also enables nodejs_compat_v2 as long as your compatibility date is 2024-09-23 or later. Learn more about the Node.js compatibility flag and v2.
The MockTracker
API in Node.js provides a means of tracking and managing mock objects in a test
environment.
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 calledconsole.log(fn.mock.calls[0].arguments)); // Recoreds the arguments that were passed each call
The full MockTracker
API is documented in the Node.js documentation for MockTracker
โ.
The Workers implementation of MockTracker
currently does not include an implementation of the Node.js mock timers API โ.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- ยฉ 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark