import { render } from "@testing-library/react"; import { beforeEach, describe, expect, it } from "vitest"; import { useLighthouseContextStore } from "@/store/lighthouse-context/store"; import { resetLighthouseContextStore } from "@/store/lighthouse-context/store.test-utils"; import { LighthouseContextContributor } from "./context-contributor"; describe("LighthouseContextContributor", () => { beforeEach(() => { resetLighthouseContextStore(); }); it("should register loaded page data and remove it on unmount", () => { // Given / When const view = render( , ); // Then expect( useLighthouseContextStore.getState().contributions["findings-total"], ).toMatchObject({ total: 42 }); // When view.unmount(); // Then expect( useLighthouseContextStore.getState().contributions["findings-total"], ).toBeUndefined(); }); it("should replace the contribution when its loaded snapshot changes", () => { const view = render( , ); view.rerender( , ); expect( useLighthouseContextStore.getState().contributions["findings-total"], ).toMatchObject({ total: 17 }); }); });