import '@testing-library/jest-dom' ; import React from 'react' ; import { render as defaultRender } from '@testing-library/react' ; import { RouterContext } from 'next/dist/shared/lib/router-context' ; import { NextRouter } from 'next/router' ; import '@testing-library/jest-dom/extend-expect' ; import { AllProviders } from '../components/AllProviders' ; export * from '@testing-library/react' ; export { default as userEvent } from '@testing-library/user-event' ; /**
 * Overloads RTL's render function with our own. Adds a customizable mock for next/router.
 */ export function render ( ui , { router = { } , ... options } = { } ) { return defaultRender ( ui , { wrapper : ( { children } ) => { return ( < RouterContext . Provider value = { { ... mockRouter , ... router } } > < AllProviders > { children } < /AllProviders> < /RouterContext.Provider>); } , ... options , } ) ; } param currentUser param apolloMocks param router param children const mockRouter = { basePath : '' , pathname : '/' , route : '/' , asPath : '/' , query : { } , push : jest . fn ( ) , replace : jest . fn ( ) , reload : jest . fn ( ) , back : jest . fn ( ) , prefetch : jest . fn ( ( ) => Promise . resolve ( ) ) , beforePopState : jest . fn ( ) , events : { on : jest . fn ( ) , off : jest . fn ( ) , emit : jest . fn ( ) , } , isFallback : false , isLocaleDomain : false , isReady : false , isPreview : false , } ; type DefaultParams = Parameters < typeof defaultRender > ; type RenderUI = DefaultParams [ 0 ] ; type RenderOptions = DefaultParams [ 1 ] & { router ? : Partial < NextRouter > ; } ;