new assert.CallTracker()
添加於:v14.2.0、v12.19.0
創建一個新的
對象,該對象可用於跟蹤函數是否被調用了特定次數。必須調用CallTracker
tracker.verify()
才能進行驗證。通常的模式是在
處理程序中調用它。process.on('exit')
import assert from 'node:assert';
import process from 'node:process';
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();
});
const assert = require('node: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();
});
相關用法
- Node.js new assert.AssertionError(options)用法及代碼示例
- Node.js new AsyncResource(type[, options])用法及代碼示例
- Node.js new stream.Duplex(options)用法及代碼示例
- Node.js new stream.Readable([options])用法及代碼示例
- Node.js new Console(options)用法及代碼示例
- Node.js new URLSearchParams(obj)用法及代碼示例
- Node.js new crypto.Certificate()用法及代碼示例
- Node.js new stream.Writable([options])用法及代碼示例
- Node.js new URLSearchParams(iterable)用法及代碼示例
- Node.js new Agent([options])用法及代碼示例
- Node.js new vm.SourceTextModule(code[, options])用法及代碼示例
- Node.js new stream.Transform([options])用法及代碼示例
- Node.js new PerformanceObserver(callback)用法及代碼示例
- Node.js new URL(input[, base])用法及代碼示例
- Node.js new URLSearchParams(string)用法及代碼示例
- Node.js net.isIP(input)用法及代碼示例
- Node.js net.createConnection(options[, connectListener])用法及代碼示例
- Node.js net.isIPv6(input)用法及代碼示例
- Node.js net.Server.address()用法及代碼示例
- Node.js net.createServer([options][, connectionListener])用法及代碼示例
- Node.js net.Server.listen()用法及代碼示例
- Node.js net.Socket.setTimeout(timeout[, callback])用法及代碼示例
- Node.js net.BlockList.check(address[, type])用法及代碼示例
- Node.js net.isIPv4(input)用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 new assert.CallTracker()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。