Skip to content

Commit

Permalink
Test Game básicos
Browse files Browse the repository at this point in the history
  • Loading branch information
lauracc97 committed Apr 26, 2024
1 parent c40f5a7 commit 2bc2ae5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const Game = () => {
setnumPreguntas(n+1);

} catch (error) {
console.log(error.response.data.error);

}
}
};
Expand Down
17 changes: 10 additions & 7 deletions webapp/src/components/Game.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
import { render, screen,cleanup } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Game from './Game';
import { BrowserRouter} from 'react-router-dom';
const jwt = require('jsonwebtoken');
const mockAxios = new MockAdapter(axios);

describe('Game', () => {
let mockAxios;

beforeEach(() => {
mockAxios = new MockAdapter(axios);
const token = jwt.sign({username: "testUsername" }, 'secret-key');
localStorage.setItem('token', token);
});

afterEach(() => {
localStorage.clear();
mockAxios.reset();
cleanup();
});

it('should render the loading text initially', () => {
it('should load the word Cargando...', () => {
render(
<BrowserRouter>
<Game />
</BrowserRouter>);
expect(screen.getByText('Cargando...')).toBeInTheDocument();
});

it('should render the question and answer options after loading', async () => {
it('should mock the question and show it on the screen', async () => {
const mockResponse = {
pregunta: 'What is the capital of France?',
correcta: 'Paris',
Expand All @@ -35,7 +39,6 @@ describe('Game', () => {
<BrowserRouter>
<Game />
</BrowserRouter>);
await waitFor(() => expect(screen.queryByText('Cargando...')).not.toBeInTheDocument());

await screen.findByText('What is the capital of France?');
expect(screen.getByText('Paris')).toBeInTheDocument();
Expand Down

0 comments on commit 2bc2ae5

Please sign in to comment.