• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

264
Vistas
React native with Axios - post method with body returns timeout

I am attempting to create a miragejs server with a post request but am receiving a timeout every time I make a call. Strangely get/delete endpoints return fine but post/put endpoints hang indefinitely resulting in jest timeout error:

Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error

My miragejs server file:

import { createServer } from "miragejs";

export function startTestAPIServer() { 
    return createServer({
        namespace: "/testing",
        routes() {
            this.get("/test", (schema) => {
                console.log("recieved request!")
                return {"foo": "get testing"}
            });

            this.post("/test", (schema, request) => {
                return {"foo": "post testing"}
            })
        }
    });
}

My test file:

import { startTestAPIServer } from "../../content/mockAPI/testAPI"
import axios from "axios"

// initiate test server
let server;

beforeEach(() => {
  server = startTestAPIServer();
})

afterEach(() => {
  server.shutdown();
})


describe("testAPI", () => {
  it("returns get request", async () => {
    var data;
    await axios
        .get("/testing/test")
        .then((res) => data = res.data)
        .catch((err) => console.log(err));
    expect(data).toEqual({"foo": "get testing"});
  })

  it("returns post request", async () => { 
    var data;
    await axios
        .post("/testing/test", {})
        .then((res) => data = res.data)
        .catch((err) => console.log(err));
      
    expect(data).toEqual({"foo": "post testing"});
  })
})

The first case passes while the second fails. I'm not sure what I'm doing wrong that could cause something like this. I am pretty sure it is not axios causing the issue, as I've logged its request and returns, and only the request is ever logged. I'm also sure that the endpoint is in fact being hit, as console logs will print from within the endpoint code block, it simply won't return for some reason. Not sure if it's relevant, but I'm also running on react native.

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is a current issue with miragejs, see here. cesar-medina-25 found a fix by adding the following to the jest setup file.

function FormDataMock() {
  this.append = function () {};
}
global.FormData = FormDataMock;
almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda