forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import { Game } from '../components/Game'; | ||
|
||
describe('Game component', () => { | ||
test('renders question correctly', () => { | ||
render(<Game goTo={(parameter) => {}} />); // Renderizar el componente Game | ||
test('renders question correctly', async () => { | ||
render(<Game goTo={(parameter) => {}} />); | ||
|
||
// Verificar que las opciones de respuesta se muestran correctamente | ||
const options = screen.getAllByRole('button'); | ||
expect(options).toHaveLength(5); // Verificar que hay cuatro opciones | ||
}); | ||
// Espera a que se cargue la pregunta | ||
await waitFor(() => screen.getByText(/Question/i)); | ||
|
||
test('clicking "Volver al menú" calls goTo function with correct argument', () => { | ||
const goToMock = jest.fn(); // Crear una función simulada | ||
render(<Game goTo={goToMock} />); // Renderizar el componente Game con la función simulada | ||
// Verifica que la pregunta se renderice correctamente | ||
expect(screen.getByText(/Question/i)).toBeInTheDocument(); | ||
|
||
// Verifica que las opciones se rendericen correctamente | ||
const options = await screen.findAllByRole('button'); | ||
expect(options).toHaveLength(4); // Ajusta esto según la cantidad de opciones que tengas en tu componente | ||
|
||
// Simular clic en el botón "Volver al menú" | ||
fireEvent.click(screen.getByText('Volver al menú')); | ||
// Simula hacer clic en la primera opción | ||
fireEvent.click(options[0]); | ||
|
||
// Espera a que se cargue la próxima pregunta | ||
await waitFor(() => screen.getByText(/Question/i)); | ||
|
||
// Verificar que la función goTo se llamó con el argumento correcto (en este caso, 1) | ||
expect(goToMock).toHaveBeenCalledWith(1); | ||
// Verifica que la próxima pregunta se renderice correctamente | ||
expect(screen.getByText(/Question/i)).toBeInTheDocument(); | ||
}); | ||
}); |