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
75
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
  • 17,433
  • 22
  • 78
  • 131
69
votes
2 answers

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
  • 4,883
  • 6
  • 15
  • 24
53
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
  • 10,619
  • 13
  • 64
  • 89
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
41
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
  • 4,072
  • 4
  • 28
  • 36
35
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
  • 1,064
  • 1
  • 15
  • 25
32
votes
9 answers

Jest has detected the following 1 open handle potentially keeping Jest from exiting: TCPSERVERWRAP

I am doing a basic end to end testing here, for the moment it's failing, but first I can't get rid of the open handle. Ran all test suites. Jest has detected the following 1 open handle potentially keeping Jest from exiting: ● TCPSERVERWRAP …
A Mehmeto
  • 1,594
  • 3
  • 22
  • 37
30
votes
10 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
  • 503
  • 2
  • 5
  • 13
26
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,198
  • 5
  • 31
  • 53
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
22
votes
5 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,603
  • 3
  • 14
  • 29
21
votes
3 answers

How to unit test file upload with Supertest -and- send a token?

How can I test a file upload with a token being sent? I'm getting back "0" instead of a confirmation of upload. This is a failed test: var chai = require('chai'); var expect = chai.expect; var config = require("../config"); // contains call to…
Christina Mitchell
  • 437
  • 2
  • 8
  • 17
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…
21
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
  • 15,446
  • 19
  • 62
  • 87
20
votes
2 answers

MSW logging warnings for unhandled Supertest requests

In my tests using Supertest and MSW I've noticed that, although they still pass successfully, MSW has started showing warnings for the requests that Supertest is making. For example (see files to reproduce at the end of the post): $ npm t >…
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
1
2 3
61 62