std/expect/_to_have_length_test.ts
2024-04-29 11:57:30 +09:00

27 lines
711 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { expect } from "./expect.ts";
import { AssertionError, assertThrows } from "@std/assert";
Deno.test("expect().toHaveLength()", () => {
expect([1, 2, 3]).toHaveLength(3);
expect("abc").toHaveLength(3);
expect([1, 2, 3]).not.toHaveLength(4);
expect("abc").not.toHaveLength(4);
assertThrows(() => {
expect([1, 2, 3]).toHaveLength(4);
}, AssertionError);
assertThrows(() => {
expect("abc").toHaveLength(4);
}, AssertionError);
assertThrows(() => {
expect([1, 2, 3]).not.toHaveLength(3);
}, AssertionError);
assertThrows(() => {
expect("abc").not.toHaveLength(3);
}, AssertionError);
});