test: guard matrix mock calls · openclaw/openclaw@1e46929
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -55,7 +55,7 @@ function expectSingleDoneEvent(events: StreamEvent[]) {
|
55 | 55 | } |
56 | 56 | |
57 | 57 | function requireMockCallArg(mock: { mock: { calls: unknown[][] } }, label: string) { |
58 | | -const call = mock.mock.calls[0]; |
| 58 | +const call = mock.mock.calls.at(0); |
59 | 59 | if (!call) { |
60 | 60 | throw new Error(`expected ${label} call`); |
61 | 61 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ const { matrixMessageActions } = await import("./actions.js");
|
15 | 15 | const profileAction = "set-profile" as ChannelMessageActionContext["action"]; |
16 | 16 | |
17 | 17 | function matrixActionCall() { |
18 | | -const call = mocks.handleMatrixAction.mock.calls[0]; |
| 18 | +const call = mocks.handleMatrixAction.mock.calls.at(0); |
19 | 19 | if (!call) { |
20 | 20 | throw new Error("expected handleMatrixAction call"); |
21 | 21 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ describe("matrix resolver adapter", () => {
|
26 | 26 | }); |
27 | 27 | |
28 | 28 | expect(resolveMatrixTargetsMock).toHaveBeenCalledTimes(1); |
29 | | -const [forwarded] = resolveMatrixTargetsMock.mock.calls[0] as unknown as [ |
| 29 | +const [forwarded] = resolveMatrixTargetsMock.mock.calls.at(0) as unknown as [ |
30 | 30 | { |
31 | 31 | accountId: string; |
32 | 32 | cfg: { channels: { matrix: Record<string, never> } }; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1512,7 +1512,7 @@ describe("matrix CLI verification commands", () => {
|
1512 | 1512 | }); |
1513 | 1513 | |
1514 | 1514 | expect(process.exitCode).toBe(1); |
1515 | | -expect(JSON.parse(String(stdoutWriteMock.mock.calls[0]?.[0]))).toEqual({ |
| 1515 | +expect(JSON.parse(String(stdoutWriteMock.mock.calls.at(0)?.[0]))).toEqual({ |
1516 | 1516 | error: "Matrix requires --homeserver", |
1517 | 1517 | }); |
1518 | 1518 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -214,7 +214,7 @@ describe("FileBackedMatrixSyncStore", () => {
|
214 | 214 | await vi.advanceTimersByTimeAsync(1); |
215 | 215 | await Promise.resolve(); |
216 | 216 | expect(writeSpy).toHaveBeenCalledTimes(1); |
217 | | -expect(writeSpy.mock.calls[0]).toEqual([ |
| 217 | +expect(writeSpy.mock.calls.at(0)).toEqual([ |
218 | 218 | storagePath, |
219 | 219 | { |
220 | 220 | version: 1, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -106,7 +106,7 @@ describe("matrix client storage paths", () => {
|
106 | 106 | |
107 | 107 | function expectFallbackMigrationSnapshot(env: NodeJS.ProcessEnv): void { |
108 | 108 | expect(maybeCreateMatrixMigrationSnapshotMock).toHaveBeenCalledTimes(1); |
109 | | -const [params] = maybeCreateMatrixMigrationSnapshotMock.mock.calls[0] ?? []; |
| 109 | +const [params] = maybeCreateMatrixMigrationSnapshotMock.mock.calls.at(0) ?? []; |
110 | 110 | expect(params).toEqual({ |
111 | 111 | env, |
112 | 112 | log: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ function expectDirectMappingWrite(
|
27 | 27 | roomIds: string[], |
28 | 28 | ) { |
29 | 29 | expect(setAccountData).toHaveBeenCalledTimes(1); |
30 | | -const [eventType, content] = setAccountData.mock.calls[0] ?? []; |
| 30 | +const [eventType, content] = setAccountData.mock.calls.at(0) ?? []; |
31 | 31 | expect(eventType).toBe(EventType.Direct); |
32 | 32 | expect((content as Record<string, string[]> | undefined)?.[remoteUserId]).toEqual(roomIds); |
33 | 33 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -169,7 +169,7 @@ describe("runMatrixStartupMaintenance", () => {
|
169 | 169 | await runMatrixStartupMaintenance(params, deps); |
170 | 170 | |
171 | 171 | expect(deps.syncMatrixOwnProfile).toHaveBeenCalledTimes(1); |
172 | | -const [profileSyncParams] = vi.mocked(deps.syncMatrixOwnProfile).mock.calls[0] ?? []; |
| 172 | +const [profileSyncParams] = vi.mocked(deps.syncMatrixOwnProfile).mock.calls.at(0) ?? []; |
173 | 173 | if (!profileSyncParams) { |
174 | 174 | throw new Error("profile sync params missing"); |
175 | 175 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ describe("Matrix IndexedDB persistence", () => {
|
89 | 89 | const restored = await restoreIdbFromDisk(snapshotPath); |
90 | 90 | expect(restored).toBe(false); |
91 | 91 | expect(warnSpy).toHaveBeenCalledTimes(1); |
92 | | -const [scope, message, error] = warnSpy.mock.calls[0] ?? []; |
| 92 | +const [scope, message, error] = warnSpy.mock.calls.at(0) ?? []; |
93 | 93 | expect(scope).toBe("IdbPersistence"); |
94 | 94 | expect(message).toBe(`Failed to restore IndexedDB snapshot from ${snapshotPath}:`); |
95 | 95 | expect(error).toBeInstanceOf(Error); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ describe("ConsoleLogger", () => {
|
16 | 16 | "Authorization: Bearer 123456:abcdefghijklmnopqrstuvwxyzABCDEFG", |
17 | 17 | ); |
18 | 18 | |
19 | | -const message = spy.mock.calls[0]?.[0]; |
| 19 | +const message = spy.mock.calls.at(0)?.[0]; |
20 | 20 | expect(typeof message).toBe("string"); |
21 | 21 | expect(message).toContain("Authorization: Bearer"); |
22 | 22 | expect(message).not.toContain("123456:abcdefghijklmnopqrstuvwxyzABCDEFG"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。