Open In App

Node.js assert tracker.verify() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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



Last Updated : 08 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads