Questions tagged [superagent]
410 questions
76
votes
5 answers
webpack dev server CORS issue
I am using webpack-dev-server v1.10.1 to boost up my Redux project and I have the options below:
contentBase: `http://${config.HOST}:${config.PORT}`,
quiet: false,
noInfo: true,
hot: true,
inline: true,
lazy: false,
publicPath:…

Hao
- 1,476
- 3
- 15
- 20
62
votes
26 answers
Uncaught Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development
Every time I submit a zone, it displays this error:
'Uncaught Error: A cross-origin error was thrown. React doesn't have
access to the actual error object in development'
It only occurs when I press on the submit zone button which I guess is…

William
- 1,107
- 2
- 11
- 18
48
votes
5 answers
How to chain http calls with superagent/supertest?
I am testing an express API with supertest.
I couldn't get multiple requests in a test case to work with supertest. Below is what i tried in a test case. But the test case seem to only execute the last call which is the HTTP GET.
it('should respond…
user3189921
40
votes
6 answers
How can you use cookies with superagent?
I'm doing cookie session management with express with something like this:
req.session.authentication = auth;
And I verify the authenticated urls with something like
if(!req.session.authentication){res.send(401);}
Now I'm building tests for the…

Kuryaki
- 981
- 2
- 8
- 18
38
votes
2 answers
Promise Error: Objects are not valid as a React child
I am trying to set the json to a state using user agent, I get the error:
Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {...}). If you meant to render a collection of children, use an array instead or…

Bomber
- 10,195
- 24
- 90
- 167
29
votes
4 answers
How to post multipart/form-data with node.js superagent
I am trying to send the content-type in my superagent post request to multipart/form-data.
var myagent = superagent.agent();
myagent
.post('http://localhost/endpoint')
.set('api_key', apikey)
.set('Content-Type', 'multipart/form-data')
…

nwkeeley
- 1,397
- 5
- 18
- 28
23
votes
5 answers
Read response output buffer/stream with supertest/superagent on node.js server
I am trying to write a test that checks whether an API route outputs a ZIP file with the correct contents.
I am using mocha and supertest for testing, and I would like to actually read the output stream/buffer, read the zip file contents and see if…

ragulka
- 4,312
- 7
- 48
- 73
21
votes
1 answer
Trying to post multipart/form-data with node.js supertest
I was trying to use Node.js supertest to test some REST API I had written. I need to send a request equivalent to the following CURL request:
curl -X POST -F api_key=KEY -F image=@my_file http://localhost:3000/v1/upload
I tried the following, but I…

Sankha Narayan Guria
- 937
- 2
- 9
- 26
20
votes
6 answers
Ensuring Express App is running before each Mocha Test
I am working on developing a REST API using ExpressJS, NodeJS, Mongoose and Mocha.
The thing is that I have an app.coffee file, thats responsible for setting up ExpressJS and connecting to Mongoose. The way I have set this up is that Mongoose is…

Haseeb Khan
- 795
- 2
- 11
- 22
18
votes
3 answers
How can I inject a custom HTTP Header into every request that SuperAgent makes?
Clearly SuperAgent supports custom HTTP headers:
request
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end(function(err, res){
if (res.ok) {
…

Jim G.
- 15,141
- 22
- 103
- 166
16
votes
1 answer
how can superagent and nock work together?
In node.js, I have trouble making superagent and nock work together. If I use request instead of superagent, it works perfectly.
Here is a simple example where superagent fails to report the mocked data:
var agent = require('superagent');
var nock =…

xa4
- 195
- 1
- 7
13
votes
2 answers
ECONNREFUSED when making GET request in app, but API returns JSON successfully
I'm writing a node app with React, using node-postgres and superagent for backend calls.
Let's say I'm making a GET request and using the JSON it returns to fill a table of students. My API looks like this:
import pg from 'pg';
import Router from…

johnprisco
- 143
- 1
- 1
- 7
11
votes
2 answers
What is the difference between Axios and SuperAgent libraries?
I am learning JavaScript and I can see, in multiple big projects, SuperAgent is being used for HTTP Request. I am using Axios for learning purpose, but wondering what makes SuperAgent different to Axios?

Ishan Patel
- 5,571
- 12
- 47
- 68
11
votes
2 answers
Axios vs Superagent
If I use Axios and Superagent to make a call to the same api one after another I get Superagent's response first in the console logs in both cases i.e if I call one first than the other and vice versa. Does that mean one is faster than the other or…

xtabbas
- 627
- 4
- 10
- 18
11
votes
4 answers
Test how API handles invalid JSON syntax request body using node.js
I would like to test how an REST API handles a POST request that has a body with invalid JSON syntax, for example a missing comma. I'm using node.js to write the API tests. I'm using frisby but I also tried supertest. No luck. With the previous…

alefteris
- 1,126
- 8
- 21