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.

717 questions
67
votes
8 answers

How to authenticate Supertest requests with Passport?

I'm using Passport.js for authentication (local strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest?
Gal Ben-Haim
  • 16,546
  • 19
  • 71
  • 127
44
votes
4 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
39
votes
4 answers

With Supertest, can I create an alternative request with some headers set by default?

I am using Supertest with Mocha to test an API developed with Node JS. And I want to do a lót of different tests on the API. With almost all of them I have to set Authorization and Content-Type headers again (because the API requires them for this…
Christiaan Westerbeek
  • 8,817
  • 12
  • 54
  • 77
38
votes
1 answer

How to send query string parameters using supertest?

I'm using supertest to send get query string parameters, how can I do that? I tried var imsServer = supertest.agent("https://example.com"); imsServer.get("/") .send({ username: username, password: password, client_id: 'Test1', …
J K
  • 2,935
  • 3
  • 12
  • 21
37
votes
4 answers

Testing requests that redirect with mocha/supertest in node

I can't seem to get the following integration test to pass in an express project using mocha, supertest, and should (and coffeescript). The test should = require('should') request = require('supertest') app = require('../../app') describe…
Feech
  • 3,952
  • 4
  • 25
  • 36
27
votes
5 answers

Trying to use supertest to check the body of response - getting an error

I am trying to use supertest for some testing. Here is the code snippet that I am trying to test: it("should create a new org with valid privileges and input with status 201", function(done) { request(app) .post("/orgs") .send({ name:…
Scott Switzer
  • 974
  • 1
  • 14
  • 25
20
votes
4 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,152
  • 7
  • 41
  • 71
18
votes
4 answers

res.body is empty in this test that uses supertest and Node.js

I am testing a Node.js API with supertest, and I cannot explain why the res.body object superset returns is empty. The data shows up in the res.text object, but not res.body, any idea how to fix this? I am using Express and…
blundin
  • 1,483
  • 3
  • 13
  • 28
17
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
  • 775
  • 6
  • 15
17
votes
2 answers

Supertest, test secure REST API

I am writing an integration test for a REST API protected by a jwt. One API operation POST /user/token is returning a jwt given a username and a password and this token is then used for a list of operations such as: GET /user/:id Where the route is…
JohnJohnGa
  • 14,494
  • 15
  • 58
  • 83
16
votes
3 answers

Reuse Supertest tests on a remote URL

I'm using MochaJS and SuperTest to test my API during development and absolutely LOVE it. However, I would like to also turn these same tests to remotely tests my staging server before pushing the code out to production. Is there a way to supply…
Shane Stillwell
  • 3,078
  • 4
  • 29
  • 52
15
votes
1 answer

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,376
  • 1
  • 10
  • 25
14
votes
6 answers

Jest testing multiple test file port 3000 already in use

I'm creating a testing for my express app. The project has multiple test files. In each module the server instance is required at beforeEach() method and closed at afterEach() method. but after testing one or two of the modules it'll raise address…
btinsae
  • 263
  • 1
  • 3
  • 12
14
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,602
  • 1
  • 28
  • 36
14
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,433
  • 1
  • 11
  • 28
1
2 3
47 48