test: guard skill workshop mock calls · openclaw/openclaw@c63b72d
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -72,8 +72,16 @@ function detailRecord(result: unknown): Record<string, unknown> {
|
72 | 72 | return details as Record<string, unknown>; |
73 | 73 | } |
74 | 74 | |
| 75 | +function mockCall(mock: { mock: { calls: unknown[][] } }, index: number, label: string) { |
| 76 | +const call = mock.mock.calls[index]; |
| 77 | +if (!call) { |
| 78 | +throw new Error(`expected ${label}`); |
| 79 | +} |
| 80 | +return call; |
| 81 | +} |
| 82 | + |
75 | 83 | function firstMockArg(mock: { mock: { calls: unknown[][] } }): Record<string, unknown> { |
76 | | -const arg = mock.mock.calls[0]?.[0]; |
| 84 | +const arg = mockCall(mock, 0, "first mock call")[0]; |
77 | 85 | if (!arg || typeof arg !== "object" || Array.isArray(arg)) { |
78 | 86 | throw new Error("expected first mock argument object"); |
79 | 87 | } |
@@ -106,8 +114,8 @@ describe("skill-workshop", () => {
|
106 | 114 | |
107 | 115 | expect(tool).toBeNull(); |
108 | 116 | expect(on.mock.calls.map(([hook]) => hook)).toEqual(["before_prompt_build", "agent_end"]); |
109 | | -expect(typeof on.mock.calls[0]?.[1]).toBe("function"); |
110 | | -expect(typeof on.mock.calls[1]?.[1]).toBe("function"); |
| 117 | +expect(typeof mockCall(on, 0, "before_prompt_build hook registration")[1]).toBe("function"); |
| 118 | +expect(typeof mockCall(on, 1, "agent_end hook registration")[1]).toBe("function"); |
111 | 119 | }); |
112 | 120 | |
113 | 121 | it("detects user corrections and creates an animated GIF proposal", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。