1'use strict'; 2require('../common'); 3const assert = require('assert'); 4 5// This test ensures that assert.CallTracker.verify() works as intended. 6 7const tracker = new assert.CallTracker(); 8 9const generic_msg = 'Functions were not called the expected number of times'; 10 11function foo() {} 12 13function bar() {} 14 15const callsfoo = tracker.calls(foo, 1); 16const callsbar = tracker.calls(bar, 1); 17 18// Expects an error as callsfoo() and callsbar() were called less than one time. 19assert.throws( 20 () => tracker.verify(), 21 { message: generic_msg } 22); 23 24callsfoo(); 25 26// Expects an error as callsbar() was called less than one time. 27assert.throws( 28 () => tracker.verify(), 29 { message: 'Expected the bar function to be executed 1 time(s) but was executed 0 time(s).' } 30); 31callsbar(); 32 33// Will throw an error if callsfoo() and callsbar isn't called exactly once. 34tracker.verify(); 35 36const callsfoobar = tracker.calls(foo, 1); 37 38callsfoo(); 39 40// Expects an error as callsfoo() was called more than once and callsfoobar() was called less than one time. 41assert.throws( 42 () => tracker.verify(), 43 { message: generic_msg } 44); 45 46callsfoobar(); 47 48 49// Expects an error as callsfoo() was called more than once 50assert.throws( 51 () => tracker.verify(), 52 { message: 'Expected the foo function to be executed 1 time(s) but was executed 2 time(s).' } 53); 54