fix(plugins/reports): stub api in ReportsView test to prevent post-teardown unhandled error
ReportDetailPanel transitively calls useReportPreview, which fires fetch() from api.ts. jsdom has no fetch, the promise rejects, and the catch handler's setError triggers a React update after the test environment is torn down — React then accesses window and the suite fails with ReferenceError. The engine failures previously masked this by failing the shard before the teardown race could surface. Mocking the api module makes the preview resolve synchronously and keeps the suite clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,21 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import * as reportsHook from "../useReports.js";
|
||||
import { ReportsView } from "../ReportsView.js";
|
||||
|
||||
// ReportDetailPanel transitively calls useReportPreview → fetch(), and jsdom
|
||||
// has no fetch. The rejection lands after teardown and React's state update
|
||||
// then references `window`, surfacing as an unhandled error that fails the
|
||||
// suite. Stub the preview API to resolve synchronously.
|
||||
vi.mock("../api.js", () => ({
|
||||
listReports: vi.fn().mockResolvedValue([]),
|
||||
getReport: vi.fn().mockResolvedValue(null),
|
||||
getReportPreviewHtml: vi.fn().mockResolvedValue(""),
|
||||
getReportExportUrl: vi.fn().mockReturnValue(""),
|
||||
approveReport: vi.fn().mockResolvedValue(null),
|
||||
rejectReport: vi.fn().mockResolvedValue(null),
|
||||
publishReport: vi.fn().mockResolvedValue(null),
|
||||
getShareBlocks: vi.fn().mockResolvedValue({}),
|
||||
}));
|
||||
|
||||
describe("ReportsView", () => {
|
||||
it("renders list and compare toggle", () => {
|
||||
vi.spyOn(reportsHook, "useReports").mockReturnValue({
|
||||
|
||||
Reference in New Issue
Block a user