import { act, render, screen, waitFor } from "@testing-library/react"; import type { ProviderValueType } from "provider"; import { Provider, useProvider } from "provider"; describe("useProvider [ Base ]", () => { const text = "test"; let values: ProviderValueType | undefined; const Page = () => { values = useProvider(); return
{text}
; }; const App = () => { return ( ); }; beforeEach(() => { values = undefined; }); describe("given app is wrapped with Provider", () => { describe("when configuration values are passed to the provider", () => { it("should receive configuration with hook", async () => { render(); await waitFor(() => { expect(values).toBeDefined(); }); }); it("should allow to modify received values", async () => { const customConfig = { useFetchConfig: { bounceTime: 99999 } }; render(); act(() => { values?.setConfig(customConfig); }); await waitFor(() => { expect(values?.config).toStrictEqual(customConfig); }); }); }); }); describe("given app is not wrapped with provider", () => { describe("when app gets rendered", () => { it("should allow to render", async () => { render(); expect(screen.getByText(text)).toBeInTheDocument(); }); it("should have default setConfig that does nothing", async () => { render(); act(() => { values?.setConfig({ useCacheConfig: { dependencyTracking: false } }); }); await waitFor(() => { expect(values?.config).toStrictEqual({}); }); }); }); }); });