当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js assert.CallTracker tracker.report()用法及代码示例


tracker.report()

添加于:v14.2.0、v12.19.0

数组包含有关未调用预期次数的函数的预期和实际调用次数的信息。

import assert from 'node:assert';

// Creates call tracker.
const tracker = new assert.CallTracker();

function func() {}

function foo() {}

// Returns a function that wraps func() that must be called exact times
// before tracker.verify().
const callsfunc = tracker.calls(func, 2);

// Returns an array containing information on callsfunc()
tracker.report();
// [
//  {
//    message: 'Expected the func function to be executed 2 time(s) but was
//    executed 0 time(s).',
//    actual: 0,
//    expected: 2,
//    operator: 'func',
//    stack: stack trace
//  }
// ]const assert = require('node:assert');

// Creates call tracker.
const tracker = new assert.CallTracker();

function func() {}

function foo() {}

// Returns a function that wraps func() that must be called exact times
// before tracker.verify().
const callsfunc = tracker.calls(func, 2);

// Returns an array containing information on callsfunc()
tracker.report();
// [
//  {
//    message: 'Expected the func function to be executed 2 time(s) but was
//    executed 0 time(s).',
//    actual: 0,
//    expected: 2,
//    operator: 'func',
//    stack: stack trace
//  }
// ]

相关用法


注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 tracker.report()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。