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

369
Views
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 answers
Answer question

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 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!