mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 21:04:45 +00:00
test: guard message hook mock calls
This commit is contained in:
@@ -106,6 +106,14 @@ const actionCases: ActionCase[] = [
|
||||
},
|
||||
];
|
||||
|
||||
function requireHookEvent(handler: ReturnType<typeof vi.fn>): InternalHookEvent {
|
||||
const call = handler.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error("expected hook handler call");
|
||||
}
|
||||
return call[0] as InternalHookEvent;
|
||||
}
|
||||
|
||||
describe("message hooks", () => {
|
||||
beforeEach(() => {
|
||||
clearInternalHooks();
|
||||
@@ -126,7 +134,7 @@ describe("message hooks", () => {
|
||||
);
|
||||
|
||||
expect(handler).toHaveBeenCalledOnce();
|
||||
const event = handler.mock.calls[0][0] as InternalHookEvent;
|
||||
const event = requireHookEvent(handler);
|
||||
expect(event.type).toBe("message");
|
||||
expect(event.action).toBe(testCase.action);
|
||||
testCase.assertContext(event.context);
|
||||
@@ -244,7 +252,7 @@ describe("message hooks", () => {
|
||||
);
|
||||
const after = new Date();
|
||||
|
||||
const event = handler.mock.calls[0][0] as InternalHookEvent;
|
||||
const event = requireHookEvent(handler);
|
||||
expect(event.timestamp).toBeInstanceOf(Date);
|
||||
expect(event.timestamp.getTime()).toBeGreaterThanOrEqual(before.getTime());
|
||||
expect(event.timestamp.getTime()).toBeLessThanOrEqual(after.getTime());
|
||||
|
||||
Reference in New Issue
Block a user