import { RouterContext , BlitzRouter , BlitzProvider } from "blitz" ; import { render as defaultRender } from "@testing-library/react" ; import { renderHook as defaultRenderHook } from "@testing-library/react-hooks" ; export * from "@testing-library/react" ; export function render ( ui , { wrapper , router , dehydratedState , ... options } = { } ) { if ( ! wrapper ) { wrapper = ( { children } ) => ( < BlitzProvider dehydratedState = { dehydratedState } > < RouterContext . Provider value = { { ... mockRouter , ... router } } > { children } < /RouterContext.Provider> < /BlitzProvider>); } return defaultRender ( ui , { wrapper , ... options } ) ; } export function renderHook ( hook , { wrapper , router , dehydratedState , ... options } = { } ) { if ( ! wrapper ) { wrapper = ( { children } ) => ( < BlitzProvider dehydratedState = { dehydratedState } > < RouterContext . Provider value = { { ... mockRouter , ... router } } > { children } < /RouterContext.Provider> < /BlitzProvider>); } return defaultRenderHook ( hook , { wrapper , ... options } ) ; } export const mockRouter = { basePath : "" , pathname : "/" , route : "/" , asPath : "/" , params : { } , query : { } , isReady : true , isLocaleDomain : false , isPreview : false , push : jest . fn ( ) , replace : jest . fn ( ) , reload : jest . fn ( ) , back : jest . fn ( ) , prefetch : jest . fn ( ) , beforePopState : jest . fn ( ) , events : { on : jest . fn ( ) , off : jest . fn ( ) , emit : jest . fn ( ) , } , isFallback : false , } ; type DefaultParams = Parameters < typeof defaultRender > ; type RenderUI = DefaultParams [ 0 ] ; type RenderOptions = DefaultParams [ 1 ] & { router ? : Partial < BlitzRouter > ; dehydratedState ? : unknown ; } ; type DefaultHookParams = Parameters < typeof defaultRenderHook > ; type RenderHook = DefaultHookParams [ 0 ] ; type RenderHookOptions = DefaultHookParams [ 1 ] & { router ? : Partial < BlitzRouter > ; dehydratedState ? : unknown ; } ;