Concepts

Injected stub

Try the free JavaScript compiler

Supplies controlled dependency behavior through an explicit parameter; tests do not contact the real dependency.

Formal Syntax & Structure

javascript syntaxjavascript
async function load(id, lookup) { return await lookup(id); }

Working Example

Example Snippetjavascript
(async () => {async function load(id,lookup){const row=await lookup(id);return row.qty;}const stub=async id=>({id,qty:3});console.log(await load("x",stub));})()
JavaScript Reference