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

Stubbing ES6 function import in mocha using sinon stub

I'm trying to stub function called on one of my routes in express Router with request from supertest library. I see that function foo is called correctly, unfortunately it is not replaced by stub function I wrote in test. Code is written in ES6 and…
ruciu
  • 672
  • 8
  • 17
9
votes
2 answers

how to check not exist header field with supertest?

If I set the express.js like this: app.set("x-powered-by", false); How to test this? .expect('X-Powered-By', '', done) will throw error: Error: expected "X-Powered-By" header field .expect('X-Powered-By', null, done) also not works. Thanks!
HaveF
  • 2,995
  • 2
  • 26
  • 36
9
votes
1 answer

SuperTest's expect vs. Chai.expect

I'm confused, so if I use SuperTest which apparently looks like it has its own expect assertion, then I don't need to worry about using Chai? Or when I require Chai, Supertest knows about it and is using it as the expect mechanism?
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
9
votes
3 answers

How to test Express.js routes with Jasmine 2.3 and SuperTest

I'm using Jasmine 2.3 installed via NPM and executed with Grunt. 'use strict'; module.exports = function(grunt) { grunt.initConfig({ package: grunt.file.readJSON('package.json'), exec: { jasmine:…
Zorin Greene
  • 197
  • 4
  • 11
9
votes
1 answer

Express JS Integration testing with Supertest and mock database

Is it possible to test an Express JS REST API using supertest but replacing the actual database connection with a mock database object? I have unit tests covering the database models and other parts of the application as well as functional tests of…
Jazzuzz
  • 490
  • 6
  • 12
8
votes
2 answers

How to test a Server Sent Events (SSE) route in NodeJS?

I have a Server Sent Events route on my NodeJS app that clients can subscribe to for getting real-time updates from the server. It looks like follows: router.get('/updates', (req, res) => { res.writeHead(200, { 'Content-Type':…
philosopher
  • 1,079
  • 2
  • 16
  • 29
8
votes
1 answer

Testing Express multer file array upload with Supertest

I have a post endpoint which uses multer and takes an array of files: router.post('/api/projects/:id/sessions', upload.array('files', 4), function(req, res, next) { ... } In test, I need to send an array of 4 files, I can't figure out how to do…
Oscar Robinson
  • 1,003
  • 9
  • 26
8
votes
2 answers

Mocha + supertest + assert: print response body on test failure

I'm using mocha, supertest, and assert to test my Express app. My Express app is run in development mode so it returns useful debug info as JSON whenever a request fails. I'd like to print this data in my test suite but only when a test fails. An…
Charles
  • 545
  • 2
  • 7
  • 14
7
votes
0 answers

How to get code coverage metrics from integration tests using serverless-offline and Supertest?

I'm building an AWS Lambda function and trying to write some integration tests for it. The Lambda function is running locally using serverless-offline plugin and simply receive a GET request with some query parameters. I'm using Jest and Supertest…
7
votes
0 answers

cannot POST /graphql (404) error when running e2e test in jest (GraphQL Federation)

I am trying to test my graphql service end to end using supertest + jest in a Nest.js application but keep getting this error: Error: cannot POST /graphql (404) I have tried many things but couldn't get the test to run completely due to that…
7
votes
4 answers

Jest / Supertest Error - Right-hand side of 'instanceof' is not callable

When using supertest like so, import app from "../../src/app"; import request from "supertest"; describe("GET / - a simple api endpoint", () => { it("Hello API Request", () => { const result = request(app) …
Terry
  • 1,621
  • 4
  • 25
  • 45
7
votes
3 answers

Extending supertest in Typescript

I'm trying to create a extension on supertest. Using what I found in question Extending SuperTest. I have this working example on javascript: const request = require('supertest'); const Test = request.Test; Test.prototype.authenticate =…
Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81
7
votes
3 answers

Node EADDRINUSE: address already in use :::3000 when testing with jest and supertest

I am trying to test my API endpoints with jest and supertest: my test routes file: const app = require('../../index') const request = require('supertest') describe('test app endpoints', ()=>{ test('index should return 200 code', async (done)…
andrzej541
  • 919
  • 1
  • 9
  • 21
7
votes
2 answers

supertest not found error testing express endpoint

I tried to set up jest, supertest, and express but failed. I have these 2 simple file index.js const express = require("express"); const app = express(); const port = 3000; app.get("/", (req, res) => res.send("Hello World!")); app.listen(port, ()…
Hanz
  • 499
  • 7
  • 18
7
votes
0 answers

Jest Memory Leak testing Express Middleware

I am attempting to unit test my authentication middleware for Express. The middleware is quite simple and can be viewed below in its entirety: const admin = require('./../config/firebase/firebase'); // Models - User const User =…
user6233283