Questions tagged [supertest]

SuperTest is a module that provides high-level abstraction for testing HTTP in node.js, using low-level API provided by super-agent.

SuperTest is a module that provides high-level abstraction for testing HTTP in node.js, using low-level API provided by super-agent.

922 questions
12
votes
4 answers

Async external function leaves open handles - Jest, Supertest, Express

I'm starting to test my application using Jest and Supertest (for endpoints). Tests work smoothly but Jest detects 2 open handles after running tests which prevents Jest from exiting cleanly. This open handles are generated by an external async…
12
votes
3 answers

request.cookies is undefined when using Supertest

I'm passing my authentication token via an HTTP-Only cookie in my NestJS API. As such, when writing some E2E tests for my Auth endpoints, I'm having an issue with cookies not being where I expect them. Here's my pared-down test…
Brandon Taylor
  • 33,823
  • 15
  • 104
  • 144
12
votes
3 answers

TypeError: Cannot read property 'address' of undefined supertest

I need some help to resolve my problem with testing on nodejs codes. I'm using mocha and supertest. I'm confused with the implementation in supertest. I don't know to resolved it. I'm trying to automate downloading a file. describe('GET…
Saitama
  • 131
  • 1
  • 1
  • 6
11
votes
2 answers

How to mock multer with supertest?

I'm writing file upload API and have some troubles with mocking multer. I'm trying to test my endpoint with supertest. it('load image', async () => { await app .post(`${apiImage}`) .set('Authorization', 'abc123') …
aprisniak
  • 302
  • 5
  • 15
11
votes
3 answers

Testing Express errors with Mocha and Supertest

I have to test for server errors (Express) in acceptance tests that can't (or shouldn't) be sent with response, for example Error: Can't set headers after they are sent. Catching an error with error handler and responding with 5XX code would…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
11
votes
2 answers

Loopback testing with supertest, mocha and models

On the Google groups post on deprecating loopback-testing there is a question that asks about providing a proper example of how testing can be achieved without loopback-testing. That thread talks about using supertest instead. Below is an attempt…
Dakotah North
  • 1,324
  • 12
  • 29
11
votes
3 answers

set ip in supertest request

with supertest, I can make a resquest to test my node.js application var request = require('supertest'); var api = require('../server').app; ... it('json response', function(done){ request(api) .get('/api') .set('Accept',…
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
11
votes
2 answers

supertest: test the redirection url

with supertest, I can test the redirection code 302 var request = require('supertest'); var app = require('../server').app; describe('test route', function(){ it('return 302', function(done){ request(app) .get('/fail_id') …
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
10
votes
2 answers

The difference between axios and supertest in NodeJS

Both Axios and Supertest can send HTTP requests to a server. But why is Supertest used for testing while Axios is used for practice API calls?
6991httam
  • 305
  • 4
  • 14
10
votes
1 answer

Jest&supertest ApI testing returning TypeError: app.address is not a function

I am currently making an API with typescript, node, express and testing with jest and supertest. I had no problem when I was using Javascript, but I recently changed my project file from JS to TS including test files, and when I start testing, I get…
Riaco
  • 301
  • 1
  • 5
  • 9
10
votes
2 answers

server.close is not a function

I have a jest supertest setup for my testing , I am trying to close server after tests are done but it is throwing error, it is saying server.close() is not a function. what is wrong here? is it issue with express or jest or supertest I am not able…
sriram hegde
  • 2,301
  • 5
  • 29
  • 43
10
votes
4 answers

How to test image upload (stream) with supertest and jest?

I have an image upload endpoint in my API that accepts application/octet-stream requests and handles these streams. I'd like to write test coverage for this endpoint but cannot figure out how to use supertest to stream an image. Here's my code so…
j_d
  • 2,818
  • 9
  • 50
  • 91
10
votes
5 answers

How to avoid timeouts in mocha testcases?

Here I am attaching my code, I am passing done callback and using supertest for request. Since I am using assert/expect in my testcase inside request.end block why I need to worry about timeout? What is mistake I am making here. it('should get…
Anupam Jakhar
  • 103
  • 1
  • 1
  • 6
10
votes
2 answers

Cant test DELETE method using mocha and supertest

I'm trying to build a RESTful API for a node app. I built the routes and everything is running fine. But when I try to test it, it cant get the DELETE method to work, despite of it working normally not under tests. Here are the codes for the server…
luizrogeriocn
  • 174
  • 1
  • 2
  • 12
9
votes
4 answers

How to print the request and response when a test fails in Jest?

I'm using Supertest and Jest to test a Node.js API. A sample test has the following format it('Read a note for a user', (done) => { request(graphqlURL) .post('/graphql') .set(baseHeaders()) .send({ query:…
dsinecos
  • 571
  • 6
  • 13
1 2
3
61 62