Last active
September 15, 2024 19:08
-
-
Save scottcorgan/4580ff7109ca1557b8955ab8d4bd6ec3 to your computer and use it in GitHub Desktop.
Testing hooks with Remix and Testing Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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