MCPcopy Create free account
hub / github.com/ampproject/amphtml / stubModule

Function stubModule

build-system/tasks/make-extension/test/test.js:8–18  ·  view source on GitHub ↗
(path, name, fn, callsFake = () => {})

Source from the content-addressed store, hash-verified

6const stubbedCalls = {};
7
8async function stubModule(path, name, fn, callsFake = () => {}) {
9 const imported = require(path);
10 const original = imported[name];
11 imported[name] = (...args) => {
12 const calls = stubbedCalls[name] || (stubbedCalls[name] = []);
13 calls.push(args);
14 return callsFake(...args);
15 };
16 await fn();
17 imported.log = original;
18}
19
20const test = (name, cb) =>
21 ava(name, (t) =>

Callers 1

testFunction · 0.85

Calls 2

fnFunction · 0.50
pushMethod · 0.45

Tested by 1

testFunction · 0.68