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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。