VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-assert-tracker-calls-function/

⇱ Node.js assert tracker.calls() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js assert tracker.calls() Function

Last Updated : 14 May, 2022

The tracker.calls() method is used to keep track of the number of times a function is executed. It returns a wrapper function that should be invoked at exact times. When tracker.verify() is executed, if the method has not been called precisely exact times, tracker.verify() will throw an exception.

Syntax:

tracker.calls([fn][, exact])

Parameters:

  • fn: The function to be monitored. A no-op function is the default value.
  • exact (number): The number of times. Its default value is 1.

Return Value: A wrapper function that wraps fn.

Example 1:

Output:

Hello World
Hello World

Example 2:

Output:

👁 Image
 

Reference: https://nodejs.org/api/assert.html#trackercallsfn-exact

Comment

Explore