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
4
votes
1 answer

Supertest test flash values with redirection

If I have the following route: app.post('/', (req, res, next) => { req.flash('errors', 'error'); return res.redirect('/'); }); And the following supertest test: describe('POST /', () => { it('should return a flash error', (done) => { …
Raphael Valois
  • 165
  • 3
  • 13
4
votes
1 answer

Using expect.any() with supertest to check response body

I'm trying to use supertest to check res.body with Jest, but the following snippet will always fail request(app) .post('/auth/signup') .send(validEmailSample) .expect(200, { success: true, message: 'registration success', token:…
Alex Tong
  • 53
  • 1
  • 6
4
votes
2 answers

Simulating request error with async function

In my express app, I declare request handlers like this(simplified here): export const CreateProduct = async (req, res, next) => { try { // ProductModel is a sequelize defined model const product = await ProductModel.create(req.body) …
borislemke
  • 8,446
  • 5
  • 41
  • 54
4
votes
0 answers

Mock Firebase Admin Auth for Unit Testing Authenticated Routes

I'm using firebase-admin for authentication on my express backend. I have a middleware that checks if requests are authenticated. public resolve(): (req, res, next) => void { return async (req, res, next) => { const header =…
Corey Cole
  • 2,262
  • 1
  • 26
  • 43
4
votes
1 answer

Multiple before() or beforEach() in mocha

I need to do multiple async calls in before() hook in mocha. I need to delete a user, then signup , verify email and finally login to get token to authenticate all other test cases. Here is my code snippet : const userInfo = { …
Girish Gupta
  • 1,241
  • 13
  • 27
4
votes
1 answer

Providing sessions when testing middleware in Express

I am attempting to test middleware functions in my Express application using supertest and nock, but am having issues where the routes I have setup are checked by an earlier piece of middleware to ensure a session property exists on the incoming req…
mindparse
  • 6,115
  • 27
  • 90
  • 191
4
votes
1 answer

testing node express endpoint and stub 3rd party api call

I have an express app like this: server.js const postsController = require('./controllers/posts_controller.js') module.exports = app = express() app.get('posts', postsController.index) posts_controller.js const post =…
dylanjha
  • 2,303
  • 4
  • 28
  • 47
4
votes
1 answer

How to test an express rest api with header parameters using mocha and supertest?

I have to test my rest api. Some routes require a value in the http requests headers for the user authentication token. I have separated my interesting bussiness logic in pure javascript code but I can't find a way to test the routes that require a…
AlexB
  • 3,518
  • 4
  • 29
  • 46
4
votes
1 answer

Possible to remove User-agent header in supertest test?

I am trying to write some Supertest test cases where the User-Agent header is sent with a value, blank, or not at all. I know I can use .set to handle setting a value for that header or '' for blank, but I am not sure how to omit the User-agent…
EdgeCase
  • 135
  • 2
  • 12
4
votes
1 answer

How to get rid of supertest's output when testing express applications?

I'm building an Express.js API and I'm using mocha and supertest for testing. However, take a look at this: root path GET / 200 5.789 ms - 19 ✓ returns 200 status code GET / 200 0.787 ms - 19 ✓ returns json mime type GET / 200 0.382 ms -…
brielov
  • 1,887
  • 20
  • 28
4
votes
2 answers

Mocha route testing not executing asynchronously

I have started working with mocha and I have a problem with one particular test case. Here is the code: var assert = require("chai").assert; var request = require('supertest'); var http = require("http"); var conf = require("../config/config"); var…
0x9BD0
  • 1,542
  • 18
  • 41
4
votes
1 answer

testing oauth authenticated routes

I'm using koa-passport & koa to handle my login and registration using twitter oauth. It works great, but I'm having difficulties understanding how I should test my authenticated routes using supertest and mocha. Most examples I have seen involve…
bento
  • 4,846
  • 8
  • 41
  • 59
4
votes
0 answers

supertest EventEmitter memory leak detected

This seems to be a common question on SO, but I've tried all of the suggestions and just can't seem to get past it. The common solution seems to be a strategically placed: process.setMaxListeners(0); But I just can't seem to figure out where to…
Ricky Nelson
  • 876
  • 10
  • 24
4
votes
1 answer

Unable to catch exception from within a supertest app request

Code example shown here: https://gist.github.com/sebinsua/8118001 (There are three failures and two passes. I would like there to be four failures and one success.) It's possible to catch AssertionErrors with mocha if thrown from normal functions,…
olive
  • 1,194
  • 1
  • 15
  • 34
4
votes
1 answer

NodeJS supertest - testing routes with certificates

I'm testing my NodeJS application with supertest. My application is asking for a certificate, with the CN of the certificate my user gets authorized against the application. While testing my first route, I got an error complaining about my self…
user1772306
  • 449
  • 1
  • 7
  • 20