From 2bc2ae5fe25d0187c4b53299d7f9d295359fd57c Mon Sep 17 00:00:00 2001 From: Laura Cordero Date: Fri, 26 Apr 2024 12:17:09 +0200 Subject: [PATCH] =?UTF-8?q?Test=20Game=20b=C3=A1sicos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Game.js | 2 +- webapp/src/components/Game.test.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 8bab445e..c2f3f39e 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -165,7 +165,7 @@ const Game = () => { setnumPreguntas(n+1); } catch (error) { - console.log(error.response.data.error); + } } }; diff --git a/webapp/src/components/Game.test.js b/webapp/src/components/Game.test.js index 8727a6fc..959f1d2b 100644 --- a/webapp/src/components/Game.test.js +++ b/webapp/src/components/Game.test.js @@ -1,21 +1,25 @@ -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( @@ -23,7 +27,7 @@ describe('Game', () => { 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', @@ -35,7 +39,6 @@ describe('Game', () => { ); - await waitFor(() => expect(screen.queryByText('Cargando...')).not.toBeInTheDocument()); await screen.findByText('What is the capital of France?'); expect(screen.getByText('Paris')).toBeInTheDocument();