es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Tag: JEST-FETCH-MOCK

Jest – Cómo probar una llamada Fetch() que devuelve una Promesa rechazada?

Tengo la siguiente función que utiliza fetch() para hacer una llamada a la API: export async function fetchCars(dealershipId) { return request(‘path/to/endpoint/’ + dealershipId) .then((response) => { if (response.ok === false) { return Promise.reject(); } return response.json(); }) .then((cars) => { return parseMyCars(cars); }); } Quiero probar cuando la llamada falla . . . Read more

Obteniendo un error al llamar async await en jest-fetch-mock

Estoy usando react-native con expo, jest-fetch-mock y graphql. Al llamar a la API, estoy obteniendo un error. Error inesperado al final del JSON de entrada api.test.js import fetch from ‘jest-fetch-mock’; import { getUserFeed } from ‘../feed’; describe(‘testing api’, () => { beforeEach(() => { fetch.resetMocks(); }); it(‘return user feed query’, . . . Read more

Cómo probar la solicitud fetch post utilizando Jest.

Cómo simular la declaración fetch usando jest export default function Login() { function LoginUser() { const requestOptions = { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, Accept: ‘application/json’, }, body: JSON.stringify({ username: username, password: password }), }; fetch(‘http://localhost:8080/post’, requestOptions) .then((response) => { if (response.status === 200) { console.log(‘éxito’); } else { . . . Read more