Skip to main content

@std/assert@1.0.19
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
License
MIT
Downloads86,594/wk
Published3 months ago (1.0.19)

Common assertion functions, especially useful for testing

function assertArrayIncludes
assertArrayIncludes<T>(
actual: ArrayLikeArg<T>,
expected: ArrayLikeArg<T>,
msg?: string
): void

Asserts that actual contains all values in expected, using deep equality for non-primitive values.

Examples

Usage with primitives

import { assertArrayIncludes } from "@std/assert";

assertArrayIncludes([1, 2, 3], [2, 3]); // Passes
assertArrayIncludes([1, 2, 3], [4]); // Throws

Usage with objects (deep equality)

import { assertArrayIncludes } from "@std/assert";

assertArrayIncludes([{ a: 1 }, { b: 2 }], [{ a: 1 }]); // Passes

Type Parameters

The element type of the arrays.

Parameters

The array-like object to search within.

The values that must be present in actual.

optional
msg: string

Optional message to display on failure.

Return Type

Throws

AssertionError

If any value in expected is not found in actual.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/assert

Import symbol

import { assertArrayIncludes } from "@std/assert";
or

Import directly with a jsr specifier

import { assertArrayIncludes } from "jsr:@std/assert";