test: guard message hook mock calls · openclaw/openclaw@afc05f8
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -106,6 +106,14 @@ const actionCases: ActionCase[] = [
|
106 | 106 | }, |
107 | 107 | ]; |
108 | 108 | |
| 109 | +function requireHookEvent(handler: ReturnType<typeof vi.fn>): InternalHookEvent { |
| 110 | +const call = handler.mock.calls.at(0); |
| 111 | +if (!call) { |
| 112 | +throw new Error("expected hook handler call"); |
| 113 | +} |
| 114 | +return call[0] as InternalHookEvent; |
| 115 | +} |
| 116 | + |
109 | 117 | describe("message hooks", () => { |
110 | 118 | beforeEach(() => { |
111 | 119 | clearInternalHooks(); |
@@ -126,7 +134,7 @@ describe("message hooks", () => {
|
126 | 134 | ); |
127 | 135 | |
128 | 136 | expect(handler).toHaveBeenCalledOnce(); |
129 | | -const event = handler.mock.calls[0][0] as InternalHookEvent; |
| 137 | +const event = requireHookEvent(handler); |
130 | 138 | expect(event.type).toBe("message"); |
131 | 139 | expect(event.action).toBe(testCase.action); |
132 | 140 | testCase.assertContext(event.context); |
@@ -244,7 +252,7 @@ describe("message hooks", () => {
|
244 | 252 | ); |
245 | 253 | const after = new Date(); |
246 | 254 | |
247 | | -const event = handler.mock.calls[0][0] as InternalHookEvent; |
| 255 | +const event = requireHookEvent(handler); |
248 | 256 | expect(event.timestamp).toBeInstanceOf(Date); |
249 | 257 | expect(event.timestamp.getTime()).toBeGreaterThanOrEqual(before.getTime()); |
250 | 258 | expect(event.timestamp.getTime()).toBeLessThanOrEqual(after.getTime()); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。