2024-07-01 05:25:42 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
import { expect } from "./expect.ts";
|
|
|
|
import { AssertionError, assertRejects, assertThrows } from "@std/assert";
|
|
|
|
|
|
|
|
Deno.test("expect().resolves.toEqual()", async () => {
|
|
|
|
await expect(Promise.resolve(42)).resolves.toEqual(42);
|
|
|
|
await expect(Promise.resolve(42)).resolves.not.toEqual(0);
|
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => expect(42).resolves.toEqual(42),
|
|
|
|
AssertionError,
|
2024-08-26 05:27:49 +00:00
|
|
|
"Expected value must be PromiseLike",
|
2024-07-01 05:25:42 +00:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => expect(null).resolves.toEqual(42),
|
|
|
|
AssertionError,
|
2024-08-26 05:27:49 +00:00
|
|
|
"Expected value must be PromiseLike",
|
2024-07-01 05:25:42 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("expect().rejects.toEqual()", async () => {
|
|
|
|
await expect(Promise.reject(42)).rejects.toEqual(42);
|
|
|
|
await expect(Promise.reject(42)).rejects.not.toEqual(0);
|
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => expect(42).rejects.toEqual(42),
|
|
|
|
AssertionError,
|
2024-08-26 05:27:49 +00:00
|
|
|
"Expected value must be a PromiseLike",
|
2024-07-01 05:25:42 +00:00
|
|
|
);
|
|
|
|
await assertRejects(
|
|
|
|
() => expect(Promise.resolve(42)).rejects.toEqual(42),
|
|
|
|
AssertionError,
|
2024-08-26 05:27:49 +00:00
|
|
|
"Promise did not reject: resolved to 42",
|
2024-07-01 05:25:42 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("expect()[nonExistentMatcher]()", () => {
|
|
|
|
assertThrows(
|
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
() => (expect(() => {}) as any)["nonExistentMatcher"](),
|
|
|
|
TypeError,
|
|
|
|
"matcher not found: nonExistentMatcher",
|
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
() => (expect(() => {}) as any)[Symbol()](),
|
|
|
|
TypeError,
|
|
|
|
"matcher not found",
|
|
|
|
);
|
|
|
|
});
|