diff --git a/src/tests/App.test.js b/src/tests/App.test.js index ea6cb2d..3514874 100644 --- a/src/tests/App.test.js +++ b/src/tests/App.test.js @@ -1,24 +1,40 @@ import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import App from '../App'; +import responseAPI from './mocks' describe('Test Rick & Morty API', () => { +const results = responseAPI.results; beforeEach(()=>{ - //Fazer o mock do fetch aqui - + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + results, + }) + }) render() }) test('Verifica se aparece o card com titulo de "Rick Sanchez"', () => { - + const h3El = screen.getByRole("heading", {name: /Rick Sanchez/i }); + expect(h3El).toBeInTheDocument(); }) test('Verifica se existem o input de texto e o botão "Buscar"', () => { - + const inputEl = screen.getByRole("textbox"); + const buttonEl = screen.getByRole("button"); + expect(inputEl).toBeInTheDocument(); + expect(buttonEl).toBeInTheDocument(); }) test('Verifica se ao buscar por "Smith" aparecem 4 cards', () => { - + const inputEl = screen.getByRole("textbox"); + const buttonEl = screen.getByRole("button"); + const h3El = screen.getAllByRole("heading", { name: /smith/i }); + + userEvent.type(inputEl, "Smith"); + userEvent.click(buttonEl); + expect(h3El).toHaveLength(4); }) })