From 9e39ee021a5ee3f46c75402823659c1ac0383c3d Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Sun, 22 Oct 2023 19:38:30 +0100 Subject: [PATCH] jest testing: fix syntax error --- .../JavaScript/Syntax/Testing_with_Jest.md | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Programming_Languages/JavaScript/Syntax/Testing_with_Jest.md b/Programming_Languages/JavaScript/Syntax/Testing_with_Jest.md index 7318cd1..0c43cfa 100644 --- a/Programming_Languages/JavaScript/Syntax/Testing_with_Jest.md +++ b/Programming_Languages/JavaScript/Syntax/Testing_with_Jest.md @@ -1,7 +1,7 @@ --- categories: - Programming Languages -tags: [javascript, testing] +tags: [javascript, testing, jest] --- # Testing with Jest @@ -158,17 +158,20 @@ Note: although we are importing `someFunction` we are not actually importing the The same approaches (with minor differences) can be used with classes: -Using inline: +Using inline (where the class is not the default export): ```js jest.mock("./SomeClass", () => { - return jest.fn().mockImplementation(() => { - return { - someFunction: jest.fn(() => "value"), - someFunctionWithParam: jest.fn((param) => ({ property: param })), - someAsyncFunction: jest.fn(() => Promise.resolve("value")), - }; - }); + return { + SomeClass: jest.fn().mockImplementation(() => { + return { + someFunction: jest.fn(() => "value"), + someFunctionWithParam: jest.fn((param) => ({ property: param })), + someAsyncFunction: jest.fn(() => Promise.resolve("value")), + someOtherFunctionThatResolves: jest.fn().mockResolvedValue("some data"), + }; + }), + }; }); ```