tracker.calls([fn][, exact])
fn
<Function> Default 无操作的函数。exact
<number> Default1
。- 返回: <Function> 封装
fn
。
预计封装函数将被精确调用 exact
次。
如果在调用 tracker.verify()
时函数没有被精确调用 exact
次,那么 tracker.verify()
将抛出错误。
const assert = require('assert');
// 创建调用跟踪器。
const tracker = new assert.CallTracker();
function func() {}
// 返回封装 func() 的函数,其必须在 tracker.verify() 之前调用准确次数。
const callsfunc = tracker.calls(func);
fn
<Function> Default A no-op function.exact
<number> Default1
.- Returns: <Function> that wraps
fn
.
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.
const assert = require('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);