Questions tagged [superagent]
410 questions
2
votes
1 answer
How to mock functions when testing with jest and superagent
I have run into an issue that files and functions cannot be mocked, that is used in a handler of an API call. This call is simulated using superagent.
Here is the code of the test
// users.itest.js
const request = require('superagent');
const get =…

donatasdev
- 33
- 1
- 4
2
votes
2 answers
While loop is not generating data randomly
I'm creating API tests with async-await using Supertest and Mocha.
In the accountsData.js file I created a function to generate random test accounts.
In the accountsHelper.js file I created a function to create unlimited accounts using a while…

Rafael C.
- 2,245
- 4
- 29
- 45
2
votes
1 answer
Change host dynamically with SuperAgent
I'm trying to write a test where SuperAgent calls multiple (sub)domains, where cookies should be shared between them. Therefore, I want to swtich the agent dynamically, ie I can't create a new agent because I want the agent to retain cookies…

mahemoff
- 44,526
- 36
- 160
- 222
2
votes
1 answer
How to use .retry of superagent in React js?
I'm posting this here because I couldn't find a good example/documentation on this subject. The official Supergent docs only say
This method has two optional arguments: number of retries (default 3) and a callback. It calls callback(err, res)…

ben
- 181
- 1
- 12
2
votes
1 answer
node https client 'GET_SERVER_HELLO:sslv3 alert handshake failure', but works in browsers
I am attempting to GET a URL. The URL works successfully in browsers. I know HTTPS in node often fails due to missing root CAs, however that error (CERT_UNTRUSTED) is not the error I am getting (GET_SERVER_HELLO:sslv3 alert handshake failure):…

mikemaccana
- 110,530
- 99
- 389
- 494
2
votes
3 answers
Fetch image in React from Node.js request
When needed, React asks for an image using Superagent :
exports.getImgFromSection=function(id,request){
request
.get('/img/'+id)
.end((error, response) => {
if (!error && response) {
…

Pol Grisart
- 179
- 4
- 13
2
votes
1 answer
Dynamically Set header for all requests ( React, super-agent )
I would like an elegant way to dynamically set a Authentication header on all requests. My current solution is using a superagent-defaults package but it dooesn't handle dynamic headers
Take the sample code below
superagentWrapper.js
import defaults…

does_not_compute
- 476
- 1
- 7
- 20
2
votes
1 answer
Which server must implement CORS?
The superagent documentation contains this entry about CORS:
For security reasons, browsers will block cross-origin requests unless the server opts-in using CORS headers. Browsers will also make extra OPTIONS requests to check what HTTP headers and…

sdgfsdh
- 33,689
- 26
- 132
- 245
2
votes
2 answers
Any way to get 4xx response body w/o try...catch while using await?
async function checkToken(token) {
const result = await superagent
.post(`${config.serviceUrl}/check_token`)
.send({token});
return result.body;
}
Default options if this call will return 401 throws an Exception, which is not what i…

Lukas Liesis
- 24,652
- 10
- 111
- 109
2
votes
1 answer
Superagent error handling React Javascript
I am working on this API React App. I am using Superagent to get the API request. But I have trouble handling the error when there is no response. I get this Uncaught (in promise) Error: Unsuccessful HTTP response. I have tried to put all the code…

antonidag
- 35
- 2
- 7
2
votes
1 answer
Handling server redirect on node server using superagent-bluebird-promise
I have a node server sitting between my java monolith (backend) and browser. the node server handles the sever side rendering of react components and all.
I am using superagent-bluebird-promise to handle xhr on the node server. Now, the node server…

ghostCoder
- 1
- 9
- 49
- 72
2
votes
2 answers
Superagent: Error: Parser is unable to parse the response
I'm using Superagent in my react app, and i'm making some call's to the IPFS api. Specifically, I am uploading files to my IPFS server. Now, everything works, When I upload one or multiple files the call goes through and the files show up in IPFS no…

Shan Robertson
- 2,742
- 3
- 25
- 43
2
votes
0 answers
Nock not intercepting request with superagent when passing response body
I am using superagent for api calls and nock is not intercepting calls when I pass JSON on reply. If I dont pass anything but just response code it works fine.
----Unit test----
import nock from 'nock'
nock('http://somehost:80').log(console.log)
…

suraj byanju
- 21
- 2
2
votes
0 answers
chai-http/superagent : set Content-Type of mulipart form field
Uploading a file in an integration test as follows:
chai.request(server.instance)
.post('/profile/photo/0')
.set('Access-Token', accessToken)
.set('API-Key', testConfig.apiKey)
.set('Content-Type',…

Jasper Blues
- 28,258
- 22
- 102
- 185
2
votes
1 answer
Using multer with superagent for uploading files from react
Im using multer for the first time and I have some trouble with it.
I would like to upload image file on my server from a react client with superagent lib.
But the req.file data is always undefined, here is my code :
Server side :
const upload =…

Paul
- 101
- 1
- 1
- 12