Challenge 3: Verifying a Callback Runs Per Item — Possible Solution ==================================================================== it("calls the callback once per item, with each item as the argument", () => { const callback = jest.fn(); const items = ["apple", "banana", "cherry"]; processItems(items, callback); expect(callback).toHaveBeenCalledTimes(3); expect(callback).toHaveBeenCalledWith("apple"); expect(callback).toHaveBeenCalledWith("banana"); expect(callback).toHaveBeenCalledWith("cherry"); }); WHY THIS WORKS AS AN ANSWER ------------------------------ jest.fn() creates a mock function with no real implementation — exactly this chapter's basic mocking mechanic — used here purely to RECORD how processItems calls it, not to do any real work. toHaveBeenCalledTimes(3) verifies the callback ran exactly once per item in the 3-item array — catching a bug where, say, the function accidentally ran the callback twice per item, or skipped the last one. Three separate toHaveBeenCalledWith(...) assertions verify each INDIVIDUAL call's argument matched the corresponding item — not just that the callback was called 3 times with SOME arguments, but that it was called with the CORRECT one each time. Using three separate assertions here (rather than trying to check all three calls in one line) keeps each check simple and its failure message specific — if one of them fails, the test output points at exactly which expected argument was missing among the recorded calls.