Skip to main content
Module

x/result_js/mod.ts>expectErr

Minimum result type port of Rust
Latest
function expectErr
import { expectErr } from "https://deno.land/x/result_js@2.0.0/mod.ts";

Returns the contained Err value.

Examples

Example 1

import { Err } from "https://deno.land/x/result_js/spec.ts";
import { expectErr } from "https://deno.land/x/result_js/operators/extract.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

const result = Err(0);
declare const message: string;

assertEquals(expectErr(result, message), 0);

Example 2

import { Ok } from "https://deno.land/x/result_js/spec.ts";
import { expectErr } from "https://deno.land/x/result_js/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";

declare const message: string;
assertThrows(() => expectErr(Ok(0), message), Error, message);

Change error constructor:

Example 3

import { Ok } from "https://deno.land/x/result_js/spec.ts";
import { expectErr } from "https://deno.land/x/result_js/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";

declare const message: string;
assertThrows(() => expectErr(Ok(0), message, RangeError), RangeError, message);

Parameters

result: Result<unknown, E>
msg: string
optional
error: ErrorConstructor = [UNSUPPORTED]