


























@@ -63,25 +63,27 @@ function expectAuthFields(auth: unknown, fields: Record<string, unknown>) {
6363expectRecordFields(requireRecord(auth, "Matrix auth"), fields);
6464}
656566+function mockCall(mock: ReturnType<typeof vi.fn>, index = 0): unknown[] {
67+const call = mock.mock.calls.at(index);
68+if (!call) {
69+throw new Error(`missing mock call ${index}`);
70+}
71+return call;
72+}
73+6674function expectSavedCredentials(
6775mock: ReturnType<typeof vi.fn>,
6876fields: Record<string, unknown>,
6977accountId: string,
7078) {
71-const call = mock.mock.calls[0] as unknown[] | undefined;
72-if (!call) {
73-throw new Error("missing save credentials call");
74-}
79+const call = mockCall(mock);
7580expectRecordFields(requireRecord(call[0], "Matrix credentials"), fields);
7681requireRecord(call[1], "Matrix credential save options");
7782expect(call[2]).toBe(accountId);
7883}
79848085function expectMatrixLoginCall(fields: Record<string, unknown>) {
81-const call = matrixDoRequestMock.mock.calls[0] as unknown[] | undefined;
82-if (!call) {
83-throw new Error("missing Matrix login call");
84-}
86+const call = mockCall(matrixDoRequestMock);
8587expect(call[0]).toBe("POST");
8688expect(call[1]).toBe("/_matrix/client/v3/login");
8789expect(call[2]).toBeUndefined();
@@ -575,7 +577,7 @@ describe("resolveMatrixAuth", () => {
575577"default",
576578);
577579const repairMeta = requireRecord(
578-repairCurrentTokenStorageMetaDeviceIdMock.mock.calls[0]?.[0],
580+mockCall(repairCurrentTokenStorageMetaDeviceIdMock).at(0),
579581"repair metadata",
580582);
581583expectRecordFields(repairMeta, {
@@ -725,7 +727,7 @@ describe("resolveMatrixAuth", () => {
725727});
726728727729expectRecordFields(
728-requireRecord(resolveConfiguredSecretInputStringMock.mock.calls[0]?.[0], "secret request"),
730+requireRecord(mockCall(resolveConfiguredSecretInputStringMock).at(0), "secret request"),
729731{
730732config: cfg,
731733value: { source: "file", provider: "matrix-file", id: "value" },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。