Skip to main content
Module

x/result_js/mod.ts>expect

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

Returns the contained Ok value.

Examples

Example 1

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

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

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

Example 2

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

declare const message: string;
assertThrows(() => expect(Err(0), message), Error, message);

Change error constructor:

Example 3

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

declare const message: string;
assertThrows(() => expect(Err(0), message, RangeError), RangeError, message);

Parameters

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