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