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

Testing binary response with supertest

I'm developing an API with express and testing it with supertest. My API endpoint is returning tar.gz file. I would like to test, if file is properly sent and it's content is correct. I'm having troubles figuring out how to retrieve data. My naive…
David Vass
  • 135
  • 7
6
votes
1 answer

test responsebody with Jest and supertest

I have a simple express http server that returns "Hello worl" when issuing a get to / And I have the following test: import request from 'supertest'; import app from '../app/app'; test('test http server', async () => { const res = await…
opensas
  • 60,462
  • 79
  • 252
  • 386
6
votes
0 answers

Express Supertest always give timeout error for errors thrown in promise

Say I have some controller logic: // registered for route POST /login function login(req, res, next) { User.findOne({username: req.body.username}).exec() .then(user => { if (user) { return bcrypt.compareAsync(req.body.password,…
Jack Ye
  • 61
  • 2
6
votes
1 answer

Why does supertest (testing express) return a status of 301 and not 200?

I have an express based restful app, which I decided to test using supertest. This is my first testing with supertest and I am confused. One of the routes is: /api/version Which returns the version: export function index(req: express.Request,…
JoelParke
  • 2,676
  • 2
  • 24
  • 38
6
votes
0 answers

Status 400: Invalid multipart payload format when testing

I have this route server.route({ method: 'POST', path: '/upload', config: { payload: { output: 'stream', parse: true, allow: 'multipart/form-data', }, handler: fileUploadHandler } }) which works perfectly fine…
Trung Nguyen
  • 71
  • 1
  • 5
6
votes
2 answers

How to test express rendering with supertest and mocha

I wanted to start testing express routes today but I can figure out how to test rendering jade views. Here is my code: Route: router.get('/', function(req: any, res: any) { res.render('index', { title: 'Express' }); }); Test: …
Ivan Erlic
  • 391
  • 1
  • 4
  • 14
6
votes
1 answer

Can't upload file to multer from supertest with authentication

I'm using multer to handle file uploads in my express app, and I'm also using node-sspi for ntlm authentication. When uploading a file with curl, all works fine. But when I try doing the same with supertest it doesn't work. Supertest does work with…
arieljannai
  • 2,124
  • 3
  • 19
  • 39
6
votes
2 answers

Is it possible to use supertest with hapi?

I'm using hapi, not express. Should supertest still work? If so, is there a quick way to change my code to get it to run? My test looks like this, based on the documentation: import tape = require('tape'); const supertest =…
Richard
  • 14,798
  • 21
  • 70
  • 103
6
votes
1 answer

Why is my jasmine test timing out before the DEFAULT_TIMEOUT_INTERVAL?

Related: Can't set timeout for jasmine Jasmine 2.4.1 My test reports a failure due to timeout, even though the timeout value appears to be greater than the reported time. I'm doing this: describe('tests content controller', function(){ …
user773737
6
votes
1 answer

Different NODE_ENV for different tests

I'm testing my API with supertest I want to check that my CSRF token protection works, and then disable it for the other tests. For this I set NODE_ENV to test or not_test app.js var csrf = require('csurf'); var app = express(); if…
IggY
  • 3,005
  • 4
  • 29
  • 54
6
votes
1 answer

How to Test PUT method using supertest and jasmine-node

I am building an API with expressjs and my routes look like this module.exports = function(app){ var book = require('../controllers/book.controller'); app.get('/api/books', book.getBooks); //get all books app.post('/api/books', book.addBook); //add…
Jibolash
  • 648
  • 1
  • 9
  • 14
6
votes
1 answer

How can I test if my Express app's response contains certain HTML tags / text?

I'm running an Express Node server, and using Mocha and Supertest to test my routes. I would like to be able to test for the existence of certain text in the response for one of my Express routes, as so: it('should display form text input',…
The Pied Pipes
  • 1,425
  • 2
  • 16
  • 29
6
votes
1 answer

Getting cookie data on an express Response object?

I am just doing some API tests and I am trying to verify that the cookie data sent down is correct, however I cannot find any documentation around getting cookies from the response object, only from the request. So is there a quick way to do this…
Grofit
  • 17,693
  • 24
  • 96
  • 176
6
votes
2 answers

How to test express form post with CSRF?

I'm trying to write a test for my server side form validation but I keep getting a Forbidden error. It seems that this needs to be a 2 step process. Step 1, acquire the CSRF value from the form. Step 2, use the CSRF value to post to the form…
Ricky Nelson
  • 876
  • 10
  • 24
6
votes
1 answer

supertest test express middleware

found the following hint on how to test middleware in express: https://github.com/visionmedia/express/blob/master/test/req.xhr.jsI was wondering why my tests were always passing. Until I noticed that when i copied the test from express they behaved…
user3224014
  • 63
  • 1
  • 4