From 5bd05287d43bb08df1ac95ff3c49d855ab68b817 Mon Sep 17 00:00:00 2001 From: Ben Heidemann Date: Sat, 10 Apr 2021 12:16:19 +0100 Subject: [PATCH] test: add mock function create helper to utils --- tests/lib/test-utils.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index fd4461a..1d7b5c3 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -159,6 +159,24 @@ const parseBJSON = json => value ); +function createMockFn(implementation = undefined) { + const calls = []; + const mockFn = function(...args) { + calls.push({ + args, + }); + if (typeof implementation === 'function') { + return implementation(...args); + } + } + Object.defineProperty(mockFn, 'calls', { + get() { + return calls; + } + }); + return mockFn; +} + module.exports = { uniqueName: uniqueName, setup: setup, @@ -172,5 +190,6 @@ module.exports = { cleanup: cleanup, typedArrayEqual: typedArrayEqual, parseBJSON, - shimIndexedDB + shimIndexedDB, + createMockFn };