Created
June 4, 2021 00:16
-
-
Save tiagolpadua/3ffa7a90560ac407f6c096f744ad7ad7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { MemoryRouter } from 'react-router'; | |
| import { render, screen } from '@testing-library/react'; | |
| import App from './App'; | |
| import { MemoryRouter } from 'react-router'; | |
| import ListagemVeiculos from './pages/ListagemVeiculos'; | |
| import ListagemUsuarios from './pages/ListagemUsuarios'; | |
| import Pagina404 from './pages/Pagina404'; | |
| import Login from './pages/Login'; | |
| jest.mock('./pages/ListagemVeiculos'); | |
| jest.mock('./pages/ListagemUsuarios'); | |
| jest.mock('./pages/Login'); | |
| jest.mock('./pages/Pagina404'); | |
| describe('Componente principal', () => { | |
| // Outros testes | |
| it('Deve redirecionar para o login se tentar acessar rota que exige autenticação', () => { | |
| localStorage.clear(); | |
| Login.mockImplementation(() => <div>Login</div>); | |
| render( | |
| <MemoryRouter initialEntries={['/usuarios']}> | |
| <App /> | |
| </MemoryRouter> | |
| ); | |
| expect(screen.getByText(/Login/i)).toBeInTheDocument(); | |
| }); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment