// eslint-disable-next-line no-restricted-syntax stackTrace: new Error(), name: fn.name || 'calls', }); const tracked = new Proxy(fn, { __proto__: null, apply(fn, thisArg, argList) { context.track(thisArg, argList); return ReflectApply(fn, thisArg, argList); }, }); this.#callChecks.add(context); this.#trackedFunctions.set(tracked, context); return tracked; } report() { const errors = []; for (const context of this.#callChecks) { const message = context.report(); if (message !== undefined) { ArrayPrototypePush(errors, message); } } return errors; } verify() { const errors = this.report(); if (errors.length === 0) { return; } const message = errors.length === 1 ? errors[0].message : 'Functions were not called the expected number of times'; throw new AssertionError({ message, details: errors, }); } } module.exports = CallTracker;