import React from 'react'; import { render } from '@testing-library/react'; import '@testing-library/jest-dom'; import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles'; import { MemoryRouter, Route, Routes } from 'react-router-dom'; import theme from '../theme'; import I18n from '../I18n'; /* This is wrapper for the render method in order to provide all required providers and not to repeat them for each test. If you want to debug a test by having a look at the current output of the component, simply import the "screen" object from this file and use the "debug()" method: test('displays the header and paragraph text', () => { render() screen.debug() }) or of a specific element in the component: test('displays the header and paragraph text', () => { render() const header = screen.getByRole('heading', { name: /travel anywhere/i }) screen.debug(header) }) More about "render" and "screen" on https://testing-library.com/docs For testing certain conditions, check out https://jestjs.io/docs/expect and for running tests, check out https://jestjs.io/docs/api. As an alternative to fireEvent there is the userEvent which may simulate better a user clicking around. Example: import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; test("radio", () => { const user = userEvent.setup(); render(
) await user.click(screen.getByLabelText("Second")); }); */ const NoRoute = (props) => { return null; }; const AllTheProviders = (initialEntries, path) => ({ children }) => { if (typeof initialEntries === 'undefined') { initialEntries = '/'; } if (typeof path === 'undefined') { path = '/'; } return ( } /> ); }; const customRender = (ui, options, initialEntries, path) => render(ui, { wrapper: AllTheProviders(initialEntries, path), ...options }); // re-export everything export * from '@testing-library/react'; // override render method export { customRender as render };