
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
Node.js - assert.verify() Function
The assert module provides a set of assertion functions for verifying invariants. The tracker.verify() function is an inbuilt function of the assert module of Node.js.
The Node.js tracker.verify() function iterates through the function(s) which are passed to the tracker.calls() function and an error will be thrown by tracker.verify() function if the function passed to tracker.calls() have not been called as per the expected number of times.
This function doesn't throw any error if the function is being called the expected number of times.
Syntax
Following is the syntax of Node.js tracker.verify() function −
tracker.verify();
Parameters
This function doesn't accept any parameters.
Return type
If a function is not called as to the expected number of times, the tracker.verify() function will throw an error.
Example
In the following example,
Initially, we are creating a call tracker object.
Then we are wrapping a function func inside wrapper function funccall.
We are not passing any value to the exact parameter of the Node.js tracker.calls() function and it takes 1 as the default value. So, it was expected that the function func should be called at least one time.
const assert = require('assert'); const tracker = new assert.CallTracker(); function func() {} const funccall = tracker.calls(func); funccall(); funccall(); tracker.verify();
Output
/home/cg/root/63a002c52763b/main.js:3 const tracker = new assert.CallTracker(); ^ TypeError: assert.CallTracker is not a constructor at Object.<anonymous> (/home/cg/root/63a002c52763b/main.js:3:17) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Note − Sometimes online compiler may not give us the expected result, so we are executing the above code locally.
As we can see in the output below, the function func is called two times so that the tracker.verify() function will throw an error.

Example
In the following example, we are passing 4 to the exact parameter of the Node.js tracker.calls() function. So, it was expected that the function func should be called at least four times.
const assert = require('assert'); const tracker = new assert.CallTracker(); function func() {} const funccall = tracker.calls(func, 4); funccall(); funccall(); tracker.verify();
Output
/home/cg/root/63a002c52763b/main.js:3 const tracker = new assert.CallTracker(); ^ TypeError: assert.CallTracker is not a constructor at Object.<anonymous> (/home/cg/root/63a002c52763b/main.js:3:17) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Note − Sometimes online compiler may not give us the expected result, so we are executing the above code locally.
As we can see in the output below, the function func is called only two times so that the tracker.verify() function will throw an error

Example
In the following example below, the function func is called as per the expected number of times.
const assert = require('assert'); const tracker = new assert.CallTracker(); function func() {} const funccall = tracker.calls(func, 4); funccall(); funccall(); funccall(); funccall(); tracker.verify();
Output
/home/cg/root/63a002c52763b/main.js:3 const tracker = new assert.CallTracker(); ^ TypeError: assert.CallTracker is not a constructor at Object.<anonymous> (/home/cg/root/63a002c52763b/main.js:3:17) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Note − Sometimes online compiler may not give us the expected result, so we are executing the above code locally.
If we compile and run the below code, the tracker.verify() function doesn't throw any error.
// Returns nothing