tracker.calls([fn][, exact])
fn<Function> 默认值: 一个空操作函数。exact<number> 默认值:1。- 返回:<Function>,它封装了
fn。
封装函数预期会被调用正好 exact 次。如果在 tracker.verify() 被调用时函数并没有被正好调用 exact 次,则 tracker.verify() 将抛出一个错误。
【The wrapper function is expected to be called exactly exact times. If the
function has not been called exactly exact times when
tracker.verify() is called, then tracker.verify() will throw an
error.】
import assert from 'node:assert';
// Creates call tracker.
const tracker = new assert.CallTracker();
function func() {}
// Returns a function that wraps func() that must be called exact times
// before tracker.verify().
const callsfunc = tracker.calls(func);const assert = require('node:assert');
// Creates call tracker.
const tracker = new assert.CallTracker();
function func() {}
// Returns a function that wraps func() that must be called exact times
// before tracker.verify().
const callsfunc = tracker.calls(func);