Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Prueba de la aplicación React, ¿cómo probar una solicitud de publicación de axios con Jest?

App.js se ve así, ¿cómo lo probaría con broma?

 handleClick = e => { axios .post( "https://api.openweathermap.org/data/2.5/weather?q=" + this.state.term + "&units=metric&appid=" + ApiKey ){...}

Sé que tengo que crear un archivo axios simulado y luego probarlo así, pero usa setState en el App.js principal. Solo quiero probar la solicitud de búsqueda/publicación de axios con broma.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente devuelva la promesa de verificar el código axios debajo del fragmento de código

 // apiActions.js const axios = require('axios'); // your api code goes here const fetchData = () => { return axios .get('https://jsonplaceholder.typicode.com/sample_url') .then(response => { return response.data; }); }; exports.fetchData = fetchData; // testSuit.js import fetchData from './apiActions.js'; // your testing code goes here test('testing api call', () => { const sampleObj = {name:'',age:39....} fetchData().then(resp => { expect(resp).toMatchObject(sampleObj) })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!