std/expect/_assertions_test.ts
eryue0220 ed79df4696
fix(expect,internal,testing): support expect.assertions (#6032)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-10-25 17:29:40 +09:00

65 lines
1.6 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { describe, it, test } from "@std/testing/bdd";
import { expect } from "./expect.ts";
Deno.test("expect.hasAssertions() API", () => {
describe("describe suite", () => {
// FIXME(eryue0220): This test should through `toThrowErrorMatchingSnapshot`
it("should throw an error", () => {
expect.hasAssertions();
});
it("should pass", () => {
expect.hasAssertions();
expect("a").toEqual("a");
});
});
it("it() suite should pass", () => {
expect.hasAssertions();
expect("a").toEqual("a");
});
// FIXME(eryue0220): This test should through `toThrowErrorMatchingSnapshot`
test("test suite should throw an error", () => {
expect.hasAssertions();
});
test("test suite should pass", () => {
expect.hasAssertions();
expect("a").toEqual("a");
});
});
Deno.test("expect.assertions() API", () => {
test("should pass", () => {
expect.assertions(2);
expect("a").not.toBe("b");
expect("a").toBe("a");
});
// FIXME(eryue0220): This test should through `toThrowErrorMatchingSnapshot`
test("should throw error", () => {
expect.assertions(1);
expect("a").not.toBe("b");
expect("a").toBe("a");
});
it("redeclare different assertion count", () => {
expect.assertions(3);
expect("a").not.toBe("b");
expect("a").toBe("a");
expect.assertions(2);
});
test("expect no assertions", () => {
expect.assertions(0);
});
// FIXME(eryue0220): This test should through `toThrowErrorMatchingSnapshot`
it("should throw an error", () => {
expect.assertions(2);
});
});