docs-v2/content/flux/v0/stdlib/testing/shoulderror.md

1.6 KiB

title description menu weight flux/v0/tags introduced
testing.shouldError() function `testing.shouldError()` calls a function that catches any error and checks that the error matches the expected value.
flux_v0_ref
name parent identifier
testing.shouldError testing testing/shouldError
101
tests
0.174.0

testing.shouldError() calls a function that catches any error and checks that the error matches the expected value.

Function type signature
(fn: () => A, want: regexp) => stream[{v: string}]

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

fn

({{< req >}}) Function to call.

want

({{< req >}}) Regular expression to match the expected error.

Examples

Test die function errors

import "testing"

testing.shouldError(fn: () => die(msg: "error message"), want: /error message/)