From 6f7ad635a65f8aa2752b9971af9e9c1fe55ba69a Mon Sep 17 00:00:00 2001 From: Lara Date: Tue, 9 Apr 2024 21:19:32 +0200 Subject: [PATCH] Test de NotFound.js --- webapp/src/components/Pages/NotFound.test.js | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 webapp/src/components/Pages/NotFound.test.js diff --git a/webapp/src/components/Pages/NotFound.test.js b/webapp/src/components/Pages/NotFound.test.js new file mode 100644 index 0000000..d51f0db --- /dev/null +++ b/webapp/src/components/Pages/NotFound.test.js @@ -0,0 +1,28 @@ +import React from 'react'; +import { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import NotFound from './NotFound'; +import { BrowserRouter as Router } from 'react-router-dom'; + +jest.useFakeTimers(); + +describe('NotFound component', () => { + test('redirects to home page after a brief delay', async () => { + const { queryByText } = render( + + + + ); + + // Verifica que el mensaje de error 404 esté presente + expect(queryByText('404 - Página no encontrada')).toBeInTheDocument(); + + // Avanza en el tiempo para simular el retraso de redirección + jest.advanceTimersByTime(2000); // Avanza en el tiempo por 2 segundos + + // Espera a que se redirija a la página de inicio + await waitFor(() => { + expect(window.location.pathname).toBe('/'); + }); + }); +}); \ No newline at end of file