assert.CallTracker 类
稳定性: 1 - 实验
此功能目前处于实验阶段,行为可能仍会发生变化。
Stability: 1 - Experimental
This feature is currently experimental and behavior might still change.
### new assert.CallTracker()
Creates a new CallTracker
object which can be used to track if functions
were called a specific number of times. The tracker.verify()
must be called
for the verification to take place. The usual pattern would be to call it in a
process.on('exit')
handler.
const assert = require('assert');
const tracker = new assert.CallTracker();
function func() {}
// callsfunc() must be called exactly 1 time before tracker.verify().
const callsfunc = tracker.calls(func, 1);
callsfunc();
// Calls tracker.verify() and verifies if all tracker.calls() functions have
// been called exact times.
process.on('exit', () => {
tracker.verify();
});