當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js assert.CallTracker tracker.verify()用法及代碼示例


tracker.verify()

添加於:v14.2.0、v12.19.0

遍曆傳遞給 tracker.calls() 的函數列表,對於未調用預期次數的函數將引發錯誤。

import assert from 'node: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);

callsfunc();

// Will throw an error since callsfunc() was only called once.
tracker.verify();const assert = require('node: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);

callsfunc();

// Will throw an error since callsfunc() was only called once.
tracker.verify();

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 tracker.verify()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。