Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js assert tracker.verify() Function

  • Last Updated : 08 Mar, 2021

The tracker.verify() method is used to verify the how many times function was actually called compared to expected number of calls. This function will throw an error if the actual and expected number of calls are not the same.

Syntax:

tracker.verify()

Parameters: This function does not accepts any parameter.

Return Value: It returns void.

Below examplesillustrate the assert tracker.verify() function in nodejs.



Example 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);
  
// called func through callsfunc only 1 time
callsfunc();
  
console.log(tracker.verify());

Output:

Example 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 only 2 times
callsfunc();
callsfunc();
  
console.log(tracker.verify());

Output:

Reference:https://nodejs.org/api/assert.html#assert_tracker_verify




My Personal Notes arrow_drop_up
Recommended Articles
Page :