Skip to content

Instantly share code, notes, and snippets.

@scottcorgan
Last active September 15, 2024 19:08
Show Gist options
  • Save scottcorgan/4580ff7109ca1557b8955ab8d4bd6ec3 to your computer and use it in GitHub Desktop.
Save scottcorgan/4580ff7109ca1557b8955ab8d4bd6ec3 to your computer and use it in GitHub Desktop.
Testing hooks with Remix and Testing Library
/**
* If have any hooks that use Remix hooks, this helper will save you headaches
*/
import { createRemixStub } from "@remix-run/testing";
import { renderHook } from "@testing-library/react";
const renderRemixHook = <T,>(callback: () => T) => {
const RemixStub = ({ children }: PropsWithChildren) => {
const Remix = createRemixStub([
{
path: "/",
Component: () => {
return children;
},
},
]);
return <Remix />;
};
return renderHook(callback, { wrapper: RemixStub });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment