Last active
March 11, 2024 15:36
-
-
Save Jessica7/362e11670ac0fccfefd17c40d1833325 to your computer and use it in GitHub Desktop.
Api
This file contains hidden or 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
| import axios from 'axios'; | |
| import { doAuthenticate } from "../api" | |
| // temos que fazer o mock de library axios para simular uma request | |
| jest.mock('axios'); | |
| const mockAxios = axios as jest.MockedFunction<typeof axios>; | |
| describe('Api functions', () => { | |
| // verifique qual o valor de data que está chegando na função dologout e crie um objeto similar ao que temos abaixo dataMock | |
| const dataMock = { | |
| client_id: "gold", | |
| grant_type: "password", | |
| password: "12345", | |
| username: "[email protected]", | |
| }; | |
| // verifique qual valor de retorno da função dologout e crei também um similar ao responseMock de acordo com o que é retornado | |
| const responseMock: any = { | |
| data: [], | |
| status: 200, | |
| statusText: "OK", | |
| }; | |
| afterEach(() => { | |
| jest.resetAllMocks(); | |
| }); | |
| test('doAuthenticate - should to do authenticate', async () => { | |
| mockAxios.mockResolvedValueOnce(responseMock); | |
| // chame a função aqui doLogout aqui abaixo e passe os valores de mock | |
| const response = await doAuthenticate(dataMock); | |
| expect(response).toEqual(responseMock); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment