Skip to content

Commit

Permalink
Update stubs example to cover both Stubscape & Throwscape correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcornelissen committed Nov 22, 2023
1 parent ab349ba commit 07c9982
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07c9982

Please sign in to comment.