tracker.calls([fn][, exact])
-
fn
<Function> 默认值:空操作函数。¥
fn
<Function> Default: A no-op function. -
exact
<number> 默认值:1
。¥
exact
<number> Default:1
. -
返回:<Function> 封装
fn
。¥Returns: <Function> that wraps
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);