test: guard messaging test helpers · openclaw/openclaw@0322821
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -491,7 +491,6 @@ function requireReactionCall(
|
491 | 491 | index: number, |
492 | 492 | ) { |
493 | 493 | const call = mock.mock.calls[index] as unknown[] | undefined; |
494 | | -expect(call).toBeDefined(); |
495 | 494 | if (!call) { |
496 | 495 | throw new Error(`missing reaction call ${index + 1}`); |
497 | 496 | } |
@@ -564,7 +563,6 @@ function createMockDraftStreamForTest() {
|
564 | 563 | |
565 | 564 | function expectPreviewEditContent(content: string) { |
566 | 565 | const call = editMessageDiscord.mock.calls[0] as unknown[] | undefined; |
567 | | -expect(call).toBeDefined(); |
568 | 566 | if (!call) { |
569 | 567 | throw new Error("missing preview edit call"); |
570 | 568 | } |
@@ -760,7 +758,6 @@ describe("processDiscordMessage ack reactions", () => {
|
760 | 758 | const resolveCall = discordTargetMocks.resolveDiscordTargetChannelId.mock.calls[0] as |
761 | 759 | | unknown[] |
762 | 760 | | undefined; |
763 | | -expect(resolveCall).toBeDefined(); |
764 | 761 | if (!resolveCall) { |
765 | 762 | throw new Error("missing Discord target resolve call"); |
766 | 763 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -74,8 +74,10 @@ function requireArray(value: unknown, label: string): Array<unknown> {
|
74 | 74 | function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) { |
75 | 75 | const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? []; |
76 | 76 | const call = calls.at(callIndex); |
77 | | -expect(call, label).toBeDefined(); |
78 | | -return call?.[argIndex]; |
| 77 | +if (!call) { |
| 78 | +throw new Error(`Expected ${label}`); |
| 79 | +} |
| 80 | +return call[argIndex]; |
79 | 81 | } |
80 | 82 | |
81 | 83 | function fetchParams(): Record<string, unknown> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,9 +16,9 @@ function expectTargetFields(
|
16 | 16 | target: unknown, |
17 | 17 | expected: { kind: string; id: string; normalized?: string }, |
18 | 18 | ): void { |
19 | | -expect(target).toBeDefined(); |
20 | | -expect(typeof target).toBe("object"); |
21 | | -expect(target).not.toBeNull(); |
| 19 | +if (!target || typeof target !== "object") { |
| 20 | + throw new Error("Expected target record"); |
| 21 | +} |
22 | 22 | const actual = target as Record<string, unknown>; |
23 | 23 | expect(actual.kind).toBe(expected.kind); |
24 | 24 | expect(actual.id).toBe(expected.id); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -147,21 +147,29 @@ function expectInvokeResponse(sendActivity: ReturnType<typeof vi.fn>, status?: n
|
147 | 147 | ); |
148 | 148 | })?.[0] as { value?: { status?: unknown } } | undefined; |
149 | 149 | |
150 | | -expect(activity).toBeDefined(); |
| 150 | +if (!activity) { |
| 151 | +throw new Error("Expected invokeResponse activity"); |
| 152 | +} |
151 | 153 | if (status !== undefined) { |
152 | | -expect(activity?.value?.status).toBe(status); |
| 154 | +expect(activity.value?.status).toBe(status); |
153 | 155 | } |
154 | 156 | } |
155 | 157 | |
156 | 158 | function expectLogFields(logFn: unknown, message: string, fields: Record<string, unknown>): void { |
157 | 159 | const calls = (logFn as { mock?: { calls?: Array<[unknown, unknown?]> } }).mock?.calls; |
158 | | -expect(calls).toBeDefined(); |
159 | | -const call = calls?.find(([text]) => text === message); |
160 | | -expect(call).toBeDefined(); |
161 | | -const meta = call?.[1] as Record<string, unknown> | undefined; |
162 | | -expect(meta).toBeDefined(); |
| 160 | +if (!calls) { |
| 161 | +throw new Error("Expected log mock calls"); |
| 162 | +} |
| 163 | +const call = calls.find(([text]) => text === message); |
| 164 | +if (!call) { |
| 165 | +throw new Error(`Expected log message: ${message}`); |
| 166 | +} |
| 167 | +const meta = call[1] as Record<string, unknown> | undefined; |
| 168 | +if (!meta) { |
| 169 | +throw new Error(`Expected log metadata for: ${message}`); |
| 170 | +} |
163 | 171 | for (const [key, value] of Object.entries(fields)) { |
164 | | -expect(meta?.[key]).toEqual(value); |
| 172 | +expect(meta[key]).toEqual(value); |
165 | 173 | } |
166 | 174 | } |
167 | 175 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,9 @@ function sendOptions(call: unknown[] | undefined): {
|
19 | 19 | mediaUrl?: string; |
20 | 20 | } { |
21 | 21 | const options = call?.[2]; |
22 | | -expect(options).toBeDefined(); |
| 22 | +if (!options) { |
| 23 | +throw new Error("Expected Slack send options"); |
| 24 | +} |
23 | 25 | return options as { |
24 | 26 | blocks?: Array<{ |
25 | 27 | block_id?: string; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。