Skip to main content
Module

x/optio/mod.ts>expect

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

Returns the contained Some value.

Examples

Example 1

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

const option = Some(0);
declare const message: string;

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

Example 2

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

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

Change error constructor:

Example 3

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

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

Parameters

option: Option<T>
msg: string
optional
error: ErrorConstructor = [UNSUPPORTED]