Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda