From e416d5891660c9d4f39892aa826b6c2f3ca31e9f Mon Sep 17 00:00:00 2001 From: dancer1325 Date: Mon, 3 Feb 2025 15:30:50 +0100 Subject: [PATCH 1/2] doc(docs.mockFunctions): use SAME JS module system --- docs/MockFunctions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/MockFunctions.md b/docs/MockFunctions.md index 0801739e8406..b5aeb3b78732 100644 --- a/docs/MockFunctions.md +++ b/docs/MockFunctions.md @@ -12,11 +12,12 @@ There are two ways to mock functions: Either by creating a mock function to use Let's imagine we're testing an implementation of a function `forEach`, which invokes a callback for each item in a supplied array. ```js title="forEach.js" -export function forEach(items, callback) { +function forEach(items, callback) { for (const item of items) { callback(item); } } +module.exports = forEach; ``` To test this function, we can use a mock function, and inspect the mock's state to ensure the callback is invoked as expected. From 48b204c458553eb15af33acccdc6c761b2183e5d Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Thu, 22 May 2025 17:10:16 +0900 Subject: [PATCH 2/2] Update MockFunctions.md --- docs/MockFunctions.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/MockFunctions.md b/docs/MockFunctions.md index b5aeb3b78732..0238bce1012e 100644 --- a/docs/MockFunctions.md +++ b/docs/MockFunctions.md @@ -12,18 +12,17 @@ There are two ways to mock functions: Either by creating a mock function to use Let's imagine we're testing an implementation of a function `forEach`, which invokes a callback for each item in a supplied array. ```js title="forEach.js" -function forEach(items, callback) { +export function forEach(items, callback) { for (const item of items) { callback(item); } } -module.exports = forEach; ``` To test this function, we can use a mock function, and inspect the mock's state to ensure the callback is invoked as expected. ```js title="forEach.test.js" -const forEach = require('./forEach'); +import { forEach } from './forEach'; const mockCallback = jest.fn(x => 42 + x);