std/expect/_to_have_been_called_test.ts
Asher Gomez 5803cc9172
BREAKING(assert): remove assert from module names (#5176)
* BREAKING(assert): remove `assert` from module names

* work

* fix

* work

* work

* tweaks

* fix
2024-07-02 13:42:40 +10:00

31 lines
802 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertThrows } from "@std/assert";
import { expect } from "./expect.ts";
import { fn } from "./fn.ts";
Deno.test("expect().toHaveBeenCalled() checks the mock call", () => {
const mockFn = fn();
mockFn();
expect(mockFn).toHaveBeenCalled();
assertThrows(
() => expect(mockFn).not.toHaveBeenCalled(),
Error,
"Expected mock function not to be called, but it was called 1 time(s)",
);
});
Deno.test("expect().toHaveBeenCalled() handles the case when the mock is not called", () => {
const mockFn = fn();
expect(mockFn).not.toHaveBeenCalled();
assertThrows(
() => expect(mockFn).toHaveBeenCalled(),
Error,
"Expected mock function to be called, but it was not called",
);
});