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

Node Mocha & Supertest: Error: ECONNREFUSED: Connection refused

I have built an api and i want to test some of the endpoints. I have a number of tests that are similar to the ones below. They are all all failing because of Error: ECONNREFUSED: Connection refused tests import { assert, expect } from…
Kay
  • 17,906
  • 63
  • 162
  • 270
5
votes
0 answers

Passport doesn't set the req.user while testing with Supertest, using cookieSession

I have an issue testing the Express app with Supertest, using the 'cookieSession' from Express. Everything works fine, when I use session from Express, but cookieSession just doesn't work with PassportJS properly. I am using PassportJS to…
spinner
  • 73
  • 7
5
votes
3 answers

Expect libarary TypeError: expect(...).toInclude is not a function

I'm guessing it's an import error somehow, but I can't seem to figure out how, expect is up to date and I can't get it too run without it saying libarary TypeError: expect(...).toInclude is not a function var request = require("supertest"); var…
user8236024
5
votes
2 answers

Mocha tests running forever

Hello all and thanks for the attention. I'm trying to run tests with mocha and supertest, and, even though things work, the tests run forever. To avoid this, I added one "process.exit(0)" in the after() method, so it can build correctly, but this…
Allan Vital
  • 376
  • 4
  • 18
5
votes
2 answers

How can you chain supertest requests when one is dependent on the other?

So right now the output is: Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises Warning: .end() was called twice. This is not supported in superagent GET /api/things 200…
Big Money
  • 9,139
  • 6
  • 26
  • 37
5
votes
1 answer

what is the difference between Mocha and Supertest?

I'm a NodeJs beginner. Anyway, I want to create an application starting by tests, like TDD approach. What is the difference between Mocha and Supertest?
user428745
  • 803
  • 1
  • 8
  • 12
5
votes
1 answer

Express middleware console output during testing with 'supertest'

This middleware is not showing up when running in Supertest: app.use((err, req, res, next) => { // WHY DOES Supertest NOT SHOW THIS ERROR?? console.log("error: ", err.message); res.status(422).send({ error: err.message }); }); I just spent a…
Michael Bruce
  • 10,567
  • 2
  • 23
  • 31
5
votes
1 answer

Typescript / Node.js - How to mock transitive dependencies for integration testing?

Let say I have an Express route which is handled by a controller. The controller uses a service and the service uses a repository to talk to a data source. I want to create an integration test using Supertest to test that route : test -> my…
electrotype
  • 8,342
  • 11
  • 59
  • 96
5
votes
0 answers

Why does Mocha not restart Express correctly when I use --watch mode?

I want to run tests on the API routes of my Express App. I use Mongoose and it's Schemas for DB operations. This is my Setup of the test (it runs successfully first, but then fails when it reloads...): const request = require('supertest'); // this…
Chris
  • 2,069
  • 3
  • 22
  • 27
5
votes
1 answer

Extending SuperTest

I like to use SuperTest to work with my auth system like this: const request = require('./valid_access_token')(require('supertest')); request(app) .get('/v1/bots') .valid_token() .expect('Content-Type', /json/) …
Stan Wiechers
  • 1,962
  • 27
  • 45
5
votes
1 answer

sails.js + mocha + supertest + sinon: how to stub sails.js controller function

I am trying to stub a sails controller function, but I don't know which object to stub. using sinon.stub(object,'funcname', function()... This is probably related to the way sails bind controller functions... Here is some code to give…
c.ga
  • 321
  • 3
  • 6
5
votes
2 answers

Setting timeouts with supertest not working

I'm trying to test my server with some code like so: describe 'POST /do/some/stuff/', -> it 'should do this thing', (done) -> request app .post '/do/some/stuff/' .timeout 10000 .expect 200 .end (err, res) -> …
limp_chimp
  • 13,475
  • 17
  • 66
  • 105
5
votes
1 answer

How to test Express Routes that render a view

I am a bit stuck trying to test some Express Routes with SuperTest. // Mocha test .. request(app) .get('/user') .expect(200) .end(function(err, res){ if (err) return done(err); done() }); ... // Router …
gumaflux
  • 330
  • 2
  • 13
5
votes
1 answer

NodeJS testing HTTPS server with supertest

I read about supertest. I managed to test two of my routes: it('notAuthorized', function (done) { request.agent(server) .get('/notAuthorized') .expect('Content-Type', /html/) .expect(200) .expect(/Not…
user1772306
  • 449
  • 1
  • 7
  • 20
4
votes
0 answers

How to mock implementation of the redis createClient function in an integration tests with jest and supertest?

I have created a unit test for a redis repository that works fine: import { RedisSecretRepository } from "../../../../src/adapters/repositories/RedisSecretRepository"; import { Secret } from "../../../../src/domain/models/Secret"; import { UrlId }…
JMir
  • 137
  • 1
  • 10