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

supertest expect(function(res){}) , Error: expected [Function] response body ??

I'm using supertest and mocha testing my express rest api. there's this test case I want to check the returned response body with a method of supertest:expect(function(res){ } ). But I'm facing an error that I can't figure out why: Error: expected…
Aaron Shen
  • 8,124
  • 10
  • 44
  • 86
0
votes
0 answers

Restful Express API passes in mocha, fails in browser; curl

I have a restful api running on localhost that I've tested in Mocha (which starts the server) - all tests seem to pass. However, if I try using POSTMAN or curl on the restful urls, it fails (see error at bottom of this page). I've tried both…
0
votes
1 answer

Testing node express app with supertest on cloud9

I can't test express apps on cloud9 with supertest : even basic tests throws ECONNREFUSED. Steps to reproduce : create a new nodejs workspace npm install express supertest create a file "fails.js" containing the following code : // Code from…
jmbarbier
  • 814
  • 8
  • 21
0
votes
1 answer

Using supertest to check didFlash after a redirect

I'm trying to test what happens when the user destroy callback receives an error for the user controller. When destroy receives an error, it does the following: flash('error', 'Can not destroy user'); redirect(path_to.users); This is the test so…
matth
  • 6,112
  • 4
  • 37
  • 43
0
votes
1 answer

How to start Locomotive server/app for integration testing?

I am converting an Express app to Locomotive and I cannot figure out how to migrate my tests. In Express, I simply did this in my /test/test.api.organization.js file: var app = require("../app").app, request = require("supertest"); should =…
ragulka
  • 4,312
  • 7
  • 48
  • 73
0
votes
1 answer

Testing a URL provided from the server in a unit test

I'm using Mocha and supertest to do some simple testing in my NodeJS server. I now want to test this scenario: Using my application in superset I make a request The response contains a URL in it I need to now test this URL is correct (via…
edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
-1
votes
0 answers

supertest issue, agent.saveCookies is not a function

Trying to save cookies for my tests. The test ought to login, then subsequent cases(other endpoints) will use the cookie test("should respond with a json object containg the user id", () => { var response= agent.post("/login") …
-1
votes
0 answers

How To Mock a Redis DB using node js for testing an endpoint using mocha or jest

Not able to mock the redis DB for testing whether the endpoint is able to store a key and a value **this is an end point that is used for testing ** const express = require('express'); const redis = require('redis'); const app = express(); const…
-1
votes
1 answer

How to mock axios calls using jest test framework in express js application

Hi have an simple express application with below structure which tries to call a 3rd party url to get some information. To test the code, I am using jest test framework and would like to know how can I mock the axios calls to 3rd party url. File…
-1
votes
1 answer

How can I call the api repeatedly in supertest?

I want to test create, findById, and GetList that express api. And I want to call create api repeatedly for test getlist function. But If I use for loop syntax, that occurred TCPWRAP error. How can I call the api repeatedly in supertest? …
DW_Cod
  • 35
  • 5
-1
votes
1 answer

Supertest+Jest does not send JSON payload

Here is my test function : describe("Create a problem", () => { describe("Create a problem with valid data", () => { it("Should create a problem", async () => { const ProblemData = { title: "Pothole on Main Street", …
tahnoon
  • 133
  • 1
  • 14
-1
votes
1 answer

How Can I test POST request with upload file?

I have a simple node.js with handlebars proyect and I started to do Tests with jest and superTest and I dont know how can I test this POST request with body and file data: app.post('/new-team', upload.single('shield'), (req, res) => { const teams…
GGrop
  • 3
  • 1
-1
votes
1 answer

Status 404 instead of 400 when testing with Superagent / Supertest / Jest

Situation I am building and testing a simple api with express. One of the routes is /api/blogs/:id, where the api should return a status 400 if the provided id is in the wrong format, and 404 if the id is not present in the database. Problem The api…
Osocman
  • 81
  • 8
-1
votes
1 answer

In an NodeJS+Express route, when an Error is thrown with a certain message, where is this message in the response?

I have the following code: index.js var express = require('express'); var router = express.Router(); router.get('/', function(req, res, next) { throw new Error("TESTING WHERE MY ERROR MESSAGE GOES IN MY RESPONSE..."); }); module.exports =…
Ed de Almeida
  • 3,675
  • 4
  • 25
  • 57
-1
votes
1 answer

Using "expect" without a matching function (with Supertest and Jest)

I recently ran into the following testing code in an Express app using Supertest and Jest: const supertest = require("supertest"); const app = require("../app"); const api = supertest(app); test("notes are returned as json", async () => { await…
bugsyb
  • 5,662
  • 7
  • 31
  • 47