📜  Node.js 断言 tracker.report()函数

📅  最后修改于: 2022-05-13 01:56:22.672000             🧑  作者: Mango

Node.js 断言 tracker.report()函数

tracker.report()方法用于获取有关未调用预期次数的函数的预期和实际调用次数的信息。

此函数返回一个 JavaScript 对象,其中包含带有堆栈跟踪的预期和实际调用次数的完整详细信息。

语法

tracker.report()

参数:此函数不带参数

返回值:它返回一个对象,其中包含带有堆栈跟踪的预期和实际调用次数的完整详细信息。

示例 1:

Javascript
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, 2);
  
console.log(tracker.report());


Javascript
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, 2);
  
// called func through callsfunc
callsfunc();
  
console.log(tracker.report());


输出:

示例 2:

Javascript

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, 2);
  
// called func through callsfunc
callsfunc();
  
console.log(tracker.report());

输出:


参考: https://nodejs.org/api/assert.html#assert_tracker_report