Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/testing/FakeInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions test/testing-fake-instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down