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

How do I add a mock session for express-session when using SuperTest?

I have the following session setup... setupSession(){ const session = { secret: process.env.SESSION_SECRET, cookie: {}, resave: false, saveUninitialized: false, }; this.app.use(expressSession(session)); } I have the following…
Jackie
  • 21,969
  • 32
  • 147
  • 289
4
votes
1 answer

How can I retrieve the cookies from a supertest request in Jest?

I'm just starting with Jest and I'm trying to test a POST/register endpoint. This endpoint sends back 2 cookies: accessToken:*jwt* and refreshToken:*jwt*. This is my test file: import server from "../server" import supertest from "supertest" import…
Tiago Brandão
  • 207
  • 3
  • 12
4
votes
1 answer

Mocking with Jest + Supertest in Typescript

I am writing a mock test case with jest in typescript & trying to mock API calls with supertest, but unable to get a mocked response in return, as I'm using Axios on the login function & even tried to mock the Axios call but got no luck. Here's my…
Satish Joshi
  • 71
  • 1
  • 7
4
votes
1 answer

How to test authentication with jwt inside a cookie with supertest, passport, and JEST

Hey guys I am currently am trying to do something similar to what is posted here: How to authenticate Supertest requests with Passport? as I would like to test other endpoints that require authentication but in addition need to pass in a jwt. Right…
Michael Gee
  • 252
  • 1
  • 4
  • 16
4
votes
1 answer

Open handle detected in Node + Express API prevents Jest from exiting

I'm trying to test a very basic API made in Node + Express with Jest and Supertest but I'm getting the following output warning: Jest has detected the following 1 open handle potentially keeping Jest from exiting: ● TCPSERVERWRAP > 34 |…
Marc Hernández
  • 318
  • 1
  • 7
4
votes
0 answers

Occassional "read ECONNRESET " problem in Node.js and MongoDB while testing

I am testing my Node.js application with Jest and Supertest. I have multiple tests but only 2 of them fail occassionally with message "read ECONNRESET". I haven't found any constant pattern in failures because sometimes they both fail, sometimes…
Ville
  • 43
  • 4
4
votes
1 answer

Jest did not exit one second after the test run has completed when using supertest and mongoose

I am using jest to test my node.js endpoints with supertest. However after running my test jest does not exit, instead it returns the following and hangs: Jest did not exit one second after the test run has completed. This usually means that there…
Kay
  • 17,906
  • 63
  • 162
  • 270
4
votes
4 answers

reset a database before each test

I'm using node and supertest for a simple app. I got SQlite3 for the local test database. I did a simple test to get a super inserted into the database. I wanted to reset the database each time a test is run. I'm looking in the docs right now and…
seattleguy
  • 327
  • 1
  • 4
  • 11
4
votes
3 answers

Jest expect doesn't catch throw from async await function

I'm testing a typescript-express ap with MongoDB and Mongoose. For this test, I'm using jest and mongo-memory-server. I'm able to test inserting new documents and retrieving existing ones into the database, but I can't catch errors when the document…
Ktr1000
  • 253
  • 5
  • 17
4
votes
0 answers

Stub action2 helper on testing action2 controller routes response supertest

I have a project on Sails.js 1 I try to use TDD on development, so I've added route testing. To prevent real API call in helpers I've mocked them via sinon So I can successfully pass tests with this code action2 controller code module.exports = { …
Pavlo Zhukov
  • 3,007
  • 3
  • 26
  • 43
4
votes
1 answer

Running supertest-fetch's test on Heroku

We'd like to run supertest-fetch's tests on Heroku before each release. Example test: import {FetchFunction, makeFetch} from 'supertest-fetch'; import {koa} from '../koa'; import {Server} from 'http'; describe('User controller', () => { let…
Dread Boy
  • 772
  • 6
  • 28
4
votes
1 answer

Getting 500 "Internal Server Error" while using Supertest

So, I've never actually implemented any testing in the past in all my projects and decided to start implementing it in a new project I'm working on. As a total beginner I'm a bit confused with the output I'm getting. When I'm using Postman. It…
Yama
  • 401
  • 1
  • 8
  • 22
4
votes
2 answers

Can you make Supertest wait for an Express handler to finish executing?

I use Supertest to test my Express apps, but I'm running into a challenge when I want my handlers to do asynchronous processing after a request is sent. Take this code, for example: const request = require('supertest'); const express =…
Ivanna
  • 1,197
  • 1
  • 12
  • 22
4
votes
1 answer

Testing API error with supertest and jest fails even though response is correct

I'm using jest 23.1.0 and supertest 3.1.0. I'm writing some tests for my backend and things have been going ok, however for a specific case of a specific route, the test is failing even though the response object seems to contain the right…
Jayce444
  • 8,725
  • 3
  • 27
  • 43
4
votes
1 answer

MongoDB connections do not close in test scenarios

I am using express and connect via the npm package "mongodb": "^3.0.10" to a mongodb. My app.ts looks like this: const app = express(); let server: http.Server; (async () => { app.use(bodyParser.json()); let db: Db; try { const…
user2534584
  • 483
  • 2
  • 8
  • 15