2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-11-21 14:52:38 +00:00
|
|
|
|
2024-07-02 03:42:40 +00:00
|
|
|
import { assertThrows } from "@std/assert";
|
2023-11-21 14:52:38 +00:00
|
|
|
import { expect } from "./expect.ts";
|
|
|
|
import { fn } from "./fn.ts";
|
|
|
|
|
2024-07-01 09:13:47 +00:00
|
|
|
Deno.test("expect().toHaveBeenCalled() checks the mock call", () => {
|
2023-11-21 14:52:38 +00:00
|
|
|
const mockFn = fn();
|
|
|
|
mockFn();
|
2024-07-01 09:13:47 +00:00
|
|
|
|
2023-11-21 14:52:38 +00:00
|
|
|
expect(mockFn).toHaveBeenCalled();
|
2024-07-01 09:13:47 +00:00
|
|
|
|
|
|
|
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",
|
|
|
|
);
|
2023-11-21 14:52:38 +00:00
|
|
|
});
|