concept stub in category javascript
appears as: stubs, stub, A stub

This is an excerpt from Manning's book Testing JavaScript Applications.
Unit tests are designed to run against functions. They are essential to assert the quality of your software at the most granular level possible, providing quick and precise feedback. These tests import your functions, feed them input, and check the output against what you expected.
Stubs record data associated with the usage of a function and change its behaviour either by providing an alternative implementation or return value.
Now that you have a
logger, modify theaddToInventoryfunction so that it logs whenever an item is added to the inventory.Listing 3.13. inventoryController.js
const logger = require("./logger"); const inventory = new Map(); const addToInventory = (item, quantity) => { if (typeof quantity !== "number") throw new Error("quantity must be a number"); const currentQuantity = inventory.get(item) || 0; const newQuantity = currentQuantity + quantity; inventory.set(item, newQuantity); logger.logInfo({ item, quantity }, "item added to the inventory"); #1 return newQuantity; }; module.exports = { inventory, addToInventory };You can see that the logging works by running `node’s REPL and executing the following code: