Skip to content

Commit

Permalink
test: Fix missed swr default test
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Aug 26, 2024
1 parent f0c257d commit 771053b
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import classifiedRoadsResponseMock from "./mocks/classifiedRoadsResponseMock";
import digitalLandResponseMock from "./mocks/digitalLandResponseMock";
import PlanningConstraints from "./Public";

vi.spyOn(SWR, "default").mockImplementation((url: any) => {
const isGISRequest = url()?.startsWith(
`${import.meta.env.VITE_APP_API_URL}/gis/`,
);
const isRoadsRequest = url()?.startsWith(
`${import.meta.env.VITE_APP_API_URL}/roads/`,
);
vi.mock("swr", () => ({
default: vi.fn((url: any) => {
const isGISRequest = url()?.startsWith(
`${import.meta.env.VITE_APP_API_URL}/gis/`,
);
const isRoadsRequest = url()?.startsWith(
`${import.meta.env.VITE_APP_API_URL}/roads/`,
);

if (isGISRequest) return { data: digitalLandResponseMock } as any;
if (isRoadsRequest) return { data: classifiedRoadsResponseMock } as any;
if (isGISRequest) return { data: digitalLandResponseMock } as any;
if (isRoadsRequest) return { data: classifiedRoadsResponseMock } as any;

return { data: null };
});
return { data: null };
}),
}));

it("renders correctly", async () => {
const handleSubmit = vi.fn();
Expand Down

0 comments on commit 771053b

Please sign in to comment.