diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-02-24 20:55:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-24 13:55:50 +0100 |
commit | 9cc7e32e37e6708980abc051f2cb71526c175d88 (patch) | |
tree | 42728035073e98745ebd022c6788ba4d4ba520fd /docs/testing.md | |
parent | dc3683c7a433bf44656063c9eee87709fbe1e7d4 (diff) |
feat: add exit sanitizer to Deno.test (#9529)
This adds an exit sanitizer to ensure that code being tested or
dependencies of that code can't accidentally call "Deno.exit"
leading to partial test runs and false results.
Diffstat (limited to 'docs/testing.md')
-rw-r--r-- | docs/testing.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/testing.md b/docs/testing.md index 8df183a34..9b53c4c82 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -92,6 +92,31 @@ Deno.test({ }); ``` +### Exit sanitizer + +There's also the exit sanitizer which ensures that tested code doesn't call +Deno.exit() signaling a false test success. + +This is enabled by default for all tests, but can be disabled by setting the +`sanitizeExit` boolean to false in thetest definition. + +```ts +Deno.test({ + name: "false success", + fn() { + Deno.exit(0); + }, + sanitizeExit: false, +}); + +Deno.test({ + name: "failing test", + fn() { + throw new Error("this test fails"); + }, +}); +``` + ## Running tests To run the test, call `deno test` with the file that contains your test |