mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
test: give every case its own mock state under a shuffled order
Cases leaned on what an earlier case set up or left behind: a once-value the code under test never consumed, an implementation swapped in and kept by clearAllMocks, a payload only another block's setup provided, the zone resolver's per-user cache, module state in a hoisted object, and a scope set one case discovered for the next. Each now resets or states what it reads.
This commit is contained in:
1 parent
4f7802ba28
commit
227c80878c
11 files changed
+90
-37
No files matched your search
@@ -52,6 +52,12 @@ import { primeLocales } from "@/__tests__/helpers/prime-locales";
|
||||
|
||||
primeLocales("de");
|
||||
|
||||
// Every case starts on an account that never set a module, whichever case
|
||||
// ran before it and left its own modules behind.
|
||||
beforeEach(() => {
|
||||
modulesRef.value = undefined;
|
||||
});
|
||||
|
||||
function renderSSR(node: React.ReactElement, locale: "en" | "de" = "de") {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale={locale}>{node}</I18nProvider>,
|
||||
@@ -162,10 +168,6 @@ describe("<DashboardHeader> — quick-add menu", () => {
|
||||
});
|
||||
|
||||
describe("<DashboardHeader> — Log workout", () => {
|
||||
beforeEach(() => {
|
||||
modulesRef.value = undefined;
|
||||
});
|
||||
|
||||
it("offers it beside the other capture entries", () => {
|
||||
modulesRef.value = { workouts: true };
|
||||
const html = renderSSR(
|
||||
@@ -187,10 +189,6 @@ describe("<DashboardHeader> — Log workout", () => {
|
||||
});
|
||||
|
||||
describe("<DashboardHeader> — every entry follows its module, as the capture picker does", () => {
|
||||
beforeEach(() => {
|
||||
modulesRef.value = undefined;
|
||||
});
|
||||
|
||||
it("withholds Log mood when the mood module is off", () => {
|
||||
modulesRef.value = { mood: false };
|
||||
const html = renderSSR(
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* off the illness page, its settings and every picker once a record held more
|
||||
* than that, and they could then be found only through search.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const calls = vi.hoisted(() => [] as string[]);
|
||||
|
||||
@@ -41,6 +41,12 @@ vi.mock("@/lib/api/api-fetch", () => ({
|
||||
import { useIllnessEpisodes } from "../use-illness";
|
||||
|
||||
describe("useIllnessEpisodes", () => {
|
||||
// Each case states its own journal and counts only its own requests.
|
||||
beforeEach(() => {
|
||||
calls.length = 0;
|
||||
journal.total = 230;
|
||||
});
|
||||
|
||||
it("reads page after page until the whole journal is in", async () => {
|
||||
const options = useIllnessEpisodes(true) as unknown as {
|
||||
queryFn: () => Promise<{ id: string }[]>;
|
||||
@@ -55,7 +61,6 @@ describe("useIllnessEpisodes", () => {
|
||||
});
|
||||
|
||||
it("stops on a full last page the route says is the end", async () => {
|
||||
calls.length = 0;
|
||||
journal.total = 200;
|
||||
const options = useIllnessEpisodes(true) as unknown as {
|
||||
queryFn: () => Promise<{ id: string }[]>;
|
||||
@@ -63,6 +68,5 @@ describe("useIllnessEpisodes", () => {
|
||||
expect(await options.queryFn()).toHaveLength(200);
|
||||
// Two full pages of 100, no third request for an empty one.
|
||||
expect(calls).toHaveLength(2);
|
||||
journal.total = 230;
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user