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
|
|
|
|
|
|
|
import { expect } from "./expect.ts";
|
|
|
|
import { fn } from "./fn.ts";
|
2024-04-29 02:57:30 +00:00
|
|
|
import { AssertionError, assertThrows } from "@std/assert";
|
2023-11-21 14:52:38 +00:00
|
|
|
|
2024-07-01 09:13:47 +00:00
|
|
|
Deno.test("expect().toHaveBeenLastCalledWith() checks the last call of mock function", () => {
|
2023-11-21 14:52:38 +00:00
|
|
|
const mockFn = fn();
|
|
|
|
|
|
|
|
mockFn(1, 2, 3);
|
|
|
|
mockFn(4, 5, 6);
|
|
|
|
|
|
|
|
expect(mockFn).toHaveBeenLastCalledWith(4, 5, 6);
|
|
|
|
|
|
|
|
expect(mockFn).not.toHaveBeenLastCalledWith(1, 2, 3);
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
expect(mockFn).toHaveBeenLastCalledWith(1, 2, 3);
|
|
|
|
}, AssertionError);
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
expect(mockFn).not.toHaveBeenLastCalledWith(4, 5, 6);
|
|
|
|
}, AssertionError);
|
|
|
|
});
|
2024-07-01 09:13:47 +00:00
|
|
|
|
|
|
|
Deno.test("expect().toHaveBeenLastCalledWith() handles the case when the mock is not called", () => {
|
|
|
|
const mockFn = fn();
|
|
|
|
|
|
|
|
expect(mockFn).not.toHaveBeenLastCalledWith(1, 2, 3);
|
|
|
|
assertThrows(
|
|
|
|
() => expect(mockFn).toHaveBeenLastCalledWith(1, 2, 3),
|
|
|
|
AssertionError,
|
2024-08-27 05:18:01 +00:00
|
|
|
"Expected mock function to be last called with 1, 2, 3, but it was not",
|
2024-07-01 09:13:47 +00:00
|
|
|
);
|
|
|
|
});
|