From 07c9982d78dda80d5de2d9d98c3b9a0e65f4a3e9 Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Wed, 22 Nov 2023 09:54:23 +0100 Subject: [PATCH] Update stubs example to cover both `Stubscape` & `Throwscape` correctly --- docs/testing.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 056cb1837..9d42a6cb0 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -16,15 +16,28 @@ mocking ([for example with Jest][jest-module-mock]). > these stubs. ```javascript -// my-module.test.js - import assert from "node:assert"; -import { Shescape as Stubscape } from "shescape/testing"; -import { functionUnderTest } from "./my-module.js"; +import { Shescape as Stubscape, Throwscape } from "shescape/testing"; + +// Test subject +function functionUnderTest(Shescape) { + const options = { + /* ... */ + }; + const rawArgs = [ + /*... */ + ]; + + const shescape = new Shescape(options); + const args = shescape.escapeAll(rawArgs); + return args; +} // Test good conditions -const stubscape = new Stubscape(); -assert.ok(functionUnderTest(stubscape)); +assert.ok(functionUnderTest(Stubscape)); + +// Test bad conditions +assert.throws(() => functionUnderTest(Throwscape)); ``` ### Why Stubs