From 2bea36e99cd931bcc068c092fe0b362c15913af3 Mon Sep 17 00:00:00 2001 From: Alexander Harding Date: Sat, 25 Jul 2026 14:09:51 -0500 Subject: [PATCH] feat: expose every recorded call on fake instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit allCalls() makes 'this action stayed local' testable. Asserting a specific route was never called can't fail when the client has no way to call it — a consumer's spec was doing exactly that — but comparing the recorded calls before and after an action checks the real claim. --- src/testing/FakeInstance.ts | 12 ++++++++++++ test/testing-fake-instance.test.ts | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/testing/FakeInstance.ts b/src/testing/FakeInstance.ts index f511633..1fe37cf 100644 --- a/src/testing/FakeInstance.ts +++ b/src/testing/FakeInstance.ts @@ -185,6 +185,18 @@ export class FakeInstance { }); } + /** + * Every request this instance received, in order. + * + * For "nothing was sent" claims: asserting a specific route was never + * called can't fail if the client has no way to call it, whereas + * comparing this list before and after an action genuinely checks that + * the action stayed local. + */ + allCalls(): RecordedCall[] { + return [...this.#calls]; + } + /** All recorded requests matching `"METHOD /path"` (query ignored). */ calls(matcher: Matcher): RecordedCall[] { return this.#calls.filter( diff --git a/test/testing-fake-instance.test.ts b/test/testing-fake-instance.test.ts index b7d6f44..b96a543 100644 --- a/test/testing-fake-instance.test.ts +++ b/test/testing-fake-instance.test.ts @@ -137,6 +137,20 @@ describe("FakeLemmyV1Instance + ThreadiverseClient round trip", () => { ]); }); + it("exposes every recorded call for 'nothing was sent' assertions", async () => { + const { client, instance } = setup(); + + await client.getPosts({}); + const before = instance.allCalls().length; + + // A local-only action must not add requests + expect(instance.allCalls()).toHaveLength(before); + expect(instance.allCalls().at(-1)?.pathname).toBe("/api/v4/post/list"); + + await client.getPosts({}); + expect(instance.allCalls().length).toBe(before + 1); + }); + it("records calls with query for assertions", async () => { const { client, instance } = setup();