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
20
votes
2 answers

NodeJS supertest access to session object

I'm testing my Node.js application with supertest. In my controller I access the session object. In order to make a valid request this session object needs to be filled with some data. Controller // determine whether it is user's own profile…
user1772306
  • 449
  • 1
  • 7
  • 20
18
votes
1 answer

Is done required in async Jest tests?

I'm having an argument with a co-worker about done() in Jest tests. He's orders of magnitude more experienced with JavaScript than I am, and I came in after async/await was generally accepted, plus came from a .NET environment, so I was used to…
Jason St. Jacques
  • 383
  • 1
  • 3
  • 14
18
votes
2 answers

Request body undefined in supertest

I am testing an express API with supertest. I am trying to pass in body parameters into the test, as can be seen in the code snippets below, but it appears that the body parameters don't get passed in correctly since I get an error message that the…
dpen82
  • 244
  • 1
  • 2
  • 13
18
votes
3 answers

How do I get the actual server error when running supertest in mocha?

I have this code using supertest and mocha: import request from 'supertest'; //.... var newGame; describe('Creating game', function() { beforeEach(function(done) { request(app) .post('/api/games') .send({ owner: 'Mr. X', …
user69715
  • 825
  • 9
  • 15
16
votes
4 answers

Mocha Supertest json response body pattern matching issue

When I make an API call I want to inspect the returned JSON for its results. I can see the body and some the static data is being checked properly, but wherever I use regular expression things are broken. Here is an example of my test: describe('get…
Daniel
  • 293
  • 4
  • 8
15
votes
3 answers

Run Jest test suites in groups

I am writing extensive tests for a new API via Jest and supertest. Prior to running the tests, I am setting up a test database and populating it with users: Test command jest --forceExit --config src/utils/testing/jest.config.js File…
j_d
  • 2,818
  • 9
  • 50
  • 91
15
votes
1 answer

mocha watching fails under npm

I have a very simple Koa application: var app = module.exports = require("koa")(); app.use(function *(){ this.body = "Koa says Hi!"; }); var port = process.env.PORT || (process.argv[2] || 3000); port = (typeof port === "number") ? port :…
Marcus Hammarberg
  • 4,762
  • 1
  • 31
  • 37
15
votes
2 answers

Testing if download is successful with supertest

I'm testing my API endpoints with supertest, and it works great, but i can't figure out how to test if a file download is successful. In my routes file i have defined the endpoint to be: app.get('/api/attachment/:id/file', attachment.getFile); and…
Martin Hallén
  • 1,492
  • 1
  • 12
  • 27
15
votes
1 answer

NodeJS HTTPS API testing with mocha and super test -"DEPTH_ZERO_SELF_SIGNED_CERT"

I need to test an API served via HTTPS with mocha and super test (the certificate are not expired) This is a gist of the server : ... var app = express(); var _options = { key: fs.readFileSync('my-key.pem');, cert:…
jay
  • 1,453
  • 1
  • 11
  • 30
14
votes
2 answers

How to mock a middleware in supertest?

I want to test if the middleware in app.js is called. Although I mock the module work.js, it still runs the original code. app.js const work = require('./work') const express = require('require') const app = express() .use(work) .use(...) …
taian.chen
  • 163
  • 1
  • 1
  • 5
14
votes
3 answers

Jest not terminating after tests complete successfully

I'm working with jest & supertest to test my api endpoints and the tests are passing with no problems; however jest is never exiting with the Done in X amount of time statement that I would normally see. I looked to make sure the --watch flag was…
rockchalkwushock
  • 1,143
  • 2
  • 9
  • 19
14
votes
2 answers

Setting Basic Auth in Mocha and SuperTest

I'm trying to set us a test to verify the username and password of a path blocked by the basic auth of a username and password. it('should receive a status code of 200 with login', function(done) { request(url) .get("/staging") …
Peter Chappy
  • 1,165
  • 4
  • 22
  • 41
14
votes
2 answers

Access to "req" Object in Supertest After a Response

Is there any way to directly access the req object in supertest, while/after the request is being tested? I want to test my passport strategies, so I want to check req.user, req.session, and perhaps others. I know I can test page redirects or flash,…
trysis
  • 8,086
  • 17
  • 51
  • 80
14
votes
1 answer

mocha supertest ECONNRESET

I'm testing a Nodejs server with Mocha and Supertest. The test suite has grown to more than 1500 tests. Suddenly, although all of the code under test still works, my test suite fails with this error: { [Error: read ECONNRESET] code: 'ECONNRESET',…
Christian Smith
  • 8,089
  • 3
  • 19
  • 18
13
votes
1 answer

Node.js / Express / Mocha / Supertest Rest API - Empty Request Body

I've looked everywhere I can to find a solution to this. The only thing I've found is an unanswered post. I apologize if I've overlooked something. The problem is that when I try to get the POST values in the /createQuestion API, the body is…
Mike DeMille
  • 342
  • 1
  • 5
  • 17
1
2
3
61 62