test: add mock function create helper to utils

This commit is contained in:
Ben Heidemann 2021-04-10 12:16:19 +01:00 committed by David Humphrey
parent 1c34abf009
commit 5bd05287d4
1 changed files with 20 additions and 1 deletions

View File

@ -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
};