Skip to content

Commit

Permalink
Update testing documentation w.r.t Throwscape (#1299)
Browse files Browse the repository at this point in the history
Update the stubs testing examples in the documentation because the old
example was incorrect for `Throwscape`. In particular `new Throwscape()`
always errors (as intended), so invoking it before calling
`functionUnderTest` is meaningless.
  • Loading branch information
ericcornelissen authored Nov 22, 2023
1 parent 2a3f9a8 commit 708fe1e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,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, Throwscape } from "shescape/testing";
import { functionUnderTest } from "./my-module.js";

// Test good conditions
const stubscape = new Stubscape();
assert.ok(functionUnderTest(stubscape));
// Test subject
function functionUnderTest(Shescape) {
const options = {
/* ... */
};
const rawArgs = [
/*... */
];

const shescape = new Shescape(options);
const args = shescape.escapeAll(rawArgs);
return args;
}

// Test good condition
assert.ok(functionUnderTest(Stubscape));

// Test bad conditions
const throwscape = new Throwscape();
assert.ok(functionUnderTest(throwscape));
// Test bad condition
assert.throws(() => functionUnderTest(Throwscape));
```

### Why Stubs
Expand Down

0 comments on commit 708fe1e

Please sign in to comment.