Test request with FormData in jest (without mocking)

I want to test a function with jest that makes a http post request to a server by using the javascript FormData. here is a minimal example of what this could look like:

    import axios from "axios";
    async function foo() {
        let bodyFormData = new FormData();
        bodyFormData.append("foo", "myfoo");
        resp = await axios({
            method: "post",
            url: "https://postman-echo.com/post",
            data: bodyFormData,
        return resp;

    describe("Test", () => {
        it("foo test", async () => {
            return foo().then(function (result) {
                // here some testing stuff ...

from my research jest cannot use the FormData(). How can i workaround that? Ive seen some solutions here on SO but all of them are somehow mocking the FormData but the probmle with that is then never a real request is send but i want to test if the real request to the real server in working. How can I do that with jest? I’ve also tried https://github.com/form-data/form-data but it is not working too

15 thoughts on “Test request with FormData in jest (without mocking)”

  1. Hey! I realize this is sort of off-topic but
    I had to ask. Does running a well-established blog like yours take
    a large amount of work? I’m completely new to running a blog however I do write in my diary
    every day. I’d like to start a blog so I will be
    able to share my experience and views online.
    Please let me know if you have any kind of ideas or tips for new
    aspiring blog owners. Appreciate it! cheap flights http://1704milesapart.tumblr.com/ cheap flights

  2. Good day! I know this is kinda off topic nevertheless I’d figured I’d
    ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa?

    My website covers a lot of the same subjects as yours and I
    believe we could greatly benefit from each other.
    If you happen to be interested feel free to send me an e-mail.
    I look forward to hearing from you! Awesome blog by the way!
    ps4 https://tinyurl.com/45xtc52b ps4 games

  3. Today, I went to the beach front with my children. I found a sea shell and gave it
    to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched
    her ear. She never wants to go back! LoL I know this is entirely
    off topic but I had to tell someone! quest bars https://www.iherb.com/search?kw=quest%20bars quest

  4. I have been surfing on-line more than three hours lately,
    but I by no means discovered any fascinating
    article like yours. It is pretty worth sufficient
    for me. In my view, if all web owners and bloggers made
    excellent content as you probably did, the net will likely be much more helpful than ever before.


Leave a Comment