Skip to content

Commit c8ff7b4

Browse files
committed
test(app): spyToBeCalledTimesAsync is specific case of general verifier
this allows arbitrary verifier functions to be passed in, with the default just being one that checks the callback count on the spy
1 parent 7b813fd commit c8ff7b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/globals.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ global.Utils = {
120120
return this.spyToBeCalledTimesAsync(spy, 1, timeout);
121121
},
122122
spyToBeCalledTimesAsync(spy, times = 2, timeout = 5000) {
123+
const verifier = function (verifiedSpy) {
124+
return verifiedSpy.callCount >= times;
125+
};
126+
return this.spyToBeCalledWithVerifierAsync(spy, verifier, timeout);
127+
},
128+
spyToBeCalledWithVerifierAsync(spy, verifier, timeout = 5000) {
123129
let interval;
124130
const { resolve, reject, promise } = Promise.defer();
125131
const timer = setTimeout(() => {
@@ -128,7 +134,7 @@ global.Utils = {
128134
}, timeout);
129135

130136
interval = setInterval(() => {
131-
if (spy.callCount >= times) {
137+
if (verifier(spy)) {
132138
clearTimeout(timer);
133139
clearInterval(interval);
134140
resolve();

0 commit comments

Comments
 (0)