test: dedupe whatsapp login mock reads · openclaw/openclaw@e1f2478
steipete
·
2026-05-13
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,6 +87,18 @@ function runtimeMessageCalls(fn: RuntimeEnv["log"]) {
|
87 | 87 | return calls.map((call) => sanitizeTerminalText(String(call[0]))); |
88 | 88 | } |
89 | 89 | |
| 90 | +function createWaSocketCall(index: number) { |
| 91 | +const call = createWaSocketMock.mock.calls[index]; |
| 92 | +if (!call) { |
| 93 | +throw new Error(`expected createWaSocket call ${index}`); |
| 94 | +} |
| 95 | +return call; |
| 96 | +} |
| 97 | + |
| 98 | +function createWaSocketOptions(index: number): { onQr?: (qr: string) => void } | undefined { |
| 99 | +return createWaSocketCall(index)[2] as { onQr?: (qr: string) => void } | undefined; |
| 100 | +} |
| 101 | + |
90 | 102 | describe("loginWeb coverage", () => { |
91 | 103 | beforeEach(() => { |
92 | 104 | vi.useFakeTimers(); |
@@ -136,13 +148,9 @@ describe("loginWeb coverage", () => {
|
136 | 148 | await loginWeb(false, waitForWaConnectionMock as never, runtime); |
137 | 149 | |
138 | 150 | expect(createWaSocketMock).toHaveBeenCalledTimes(2); |
139 | | -expect(createWaSocketMock.mock.calls.at(0)?.[0]).toBe(false); |
140 | | -const initialOpts = createWaSocketMock.mock.calls.at(0)?.[2] as |
141 | | -| { onQr?: (qr: string) => void } |
142 | | -| undefined; |
143 | | -const restartOpts = createWaSocketMock.mock.calls.at(1)?.[2] as |
144 | | -| { onQr?: (qr: string) => void } |
145 | | -| undefined; |
| 151 | +expect(createWaSocketCall(0)[0]).toBe(false); |
| 152 | +const initialOpts = createWaSocketOptions(0); |
| 153 | +const restartOpts = createWaSocketOptions(1); |
146 | 154 | expect(initialOpts?.onQr).toBe(restartOpts?.onQr); |
147 | 155 | |
148 | 156 | initialOpts?.onQr?.("initial-qr"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。