Skip to content

Instantly share code, notes, and snippets.

@akinncar
Created July 10, 2021 01:20
Show Gist options
  • Save akinncar/6dbc7d47a6cda6853c2be40ad0bc3134 to your computer and use it in GitHub Desktop.
Save akinncar/6dbc7d47a6cda6853c2be40ad0bc3134 to your computer and use it in GitHub Desktop.
Mock contexts on testing library
import '__mocks__/broadcast'
import { ReactChildren, ReactChild } from 'react'
import { render } from '@testing-library/react'
import { GlobalStyles } from 'styles'
import { ToastContainer } from 'components/Toast'
import { AuthProvider } from 'contexts/AuthContext'
import { SidebarProvider } from 'contexts/SidebarContext'
function customRender(children: ReactChild | ReactChildren) {
return render(
<>
<ToastContainer />
<GlobalStyles />
<AuthProvider>
<SidebarProvider>{children}</SidebarProvider>
</AuthProvider>
</>
)
}
export * from '@testing-library/react'
export { customRender as render }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment