question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestBody is string `"[object Object]"`

See original GitHub issue

Given the following fetch:

const formData = new FormData();
formData.append('test', 'true');

fetch('http://localhost/api/test', {method: 'POST', body: formData});

When I mock it with nock:

nock('http://localhost')
  .post('/api/test')
  .reply(function(uri, requestBody) {
    console.log(typeof requestBody, requestBody); // string [object Object]
  });

the requestBody is "[object Object]". Is that normal? How can I inspect FormData posted with nock?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sirdavidwongcommented, Jan 24, 2017

Gotcha, ended up doing the same thing 😃 Thanks @evandavis !

1reaction
evandaviscommented, Jan 23, 2017

@sirdavidwong not exactly; we ended up writing a custom stringifier based on the npm version of form-data for our tests. Not ideal. (I believe the issue is in how FormData converts to string outside the browser.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the String coming in POST request body ...
Cause. You are making double serialization. call = ApiClient.getInstance().getMyApi().callLogin(gson.toJson(userData));.
Read more >
Spring's RequestBody and ResponseBody Annotations
The @ResponseBody annotation tells a controller that the object returned is automatically serialized into JSON and passed back into the ...
Read more >
Get HTTP POST Body in Spring Boot with @RequestBody
The @RequestBody annotation allows us to retrieve the request's body. We can then return it as a String or deserialize it into a...
Read more >
Describing Request Body
schema that describes the body data type and structure. The data type is usually an object, but can also be a primitive (such...
Read more >
The @RequestBody Annotation
The @RequestBody annotation tells Spring to deserialize an incoming request body into an object passed as a parameter to the handler method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found