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

NodeJS unit testing with Mocha and Supertest - `assert` does not seem working as expected?

assert does not seem working as expected. This is my package.json: "devDependencies": { "babel-eslint": "^7.2.3", "backpack-core": "^0.4.1", "mocha": "^3.5.0", "supertest": "^3.0.0" }, "scripts": { "test":…
Run
  • 54,938
  • 169
  • 450
  • 748
0
votes
1 answer

Not getting a response when I should be getting it from API?

I am using mocha for getting the response of this API: "http://reqres.in/api/users?page=1" I am getting a response when I use this request in POSTMAN: However when using the same request in mocha to get a response (token in this case). I am getting…
Sammy
  • 77
  • 2
  • 9
0
votes
1 answer

Jest test cases are not failing as well not passing

My Package.json code: "dependencies": { "gulp-jest": "^2.0.0", "jest-cli": "^20.0.4", "supertest": "^1.2.0" } "scripts": { "test": "gulp test" } my gulpfile test tasks are as gulp.task('run-tests', (done) => { …
Nikita S
  • 139
  • 2
  • 11
0
votes
1 answer

Authorization is not allowed by Access-Control-Allow-Headers

I'm using create-react-app and trying to figure out what I'm doing wrong here. I created an integration test in mocha using supertest which works fine: it.only('Can get a list of users', async () => { const uri = '/users' …
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
0
votes
1 answer

Mocha with chai and supertest: expected undefined to equal

I wrote the unit tests: var app = require('../server'); var chai = require('chai'); var supertest = require("supertest")(app); var GoogleUrl = require('google-url'); var config = require('../config'); var expect = chai.expect; describe('Urls…
Aleksei Korkoza
  • 427
  • 7
  • 22
0
votes
2 answers

NodeJs: next is not function

I try to write the unit tests using Mocha, Chai and Supertest, but now, unfortunately, unsuccessfully. I have next route: var express = require('express'); var GoogleUrl = require('google-url'); var _ = require('lodash'); var token =…
Aleksei Korkoza
  • 427
  • 7
  • 22
0
votes
1 answer

Supertest request with CSRF fails

I have an Express 4 application that makes user of csurf for CSRF protection on API routes. The application is working perfectly and CSRF protection is indeed working where requests without the csrf-token header will give the appropriate error. I…
kiyui
  • 375
  • 3
  • 14
0
votes
1 answer

What is Expect function to validate schema in JEST and Supertest?

like in chakram testing expect(WallObject).to.have.schema(expectedSchema). Similarly which function is there in Jest? I am using jest with supertest.
0
votes
1 answer

Back-end tests with elasticsearch fails without setTimeout

I am writing tests for back-end which uses MongoDB and Elasticsearch. The problem is that without wrapping test with setTimeout test fails, and it looks like elasticsearch can't index mock data into db before test. Here is the code: let…
0
votes
0 answers

Javascript destructuring of a supertest HTTP API response

I am running Supertest, Jasmine and Chai to auto-test an HTTP API. Expectations like this work: .expect( function(response) { expect(response.body.minVersion).to.equal(undefined) …
cham
  • 8,666
  • 9
  • 48
  • 69
0
votes
1 answer

Nock - Bodies don't match

Why does Nock give me an error saying that bodies don't match?? here is my code. it('Should Delete /user/removeuserskills', function(done){ mockRequest .delete('/user/removeuserskills',{skill:'accountant'}) .reply(201,{ …
user3450754
  • 115
  • 1
  • 1
  • 12
0
votes
1 answer

Supertest not returning correct status

Having an issue getting supertest to assert the proper status response. What am I doing wrong? /// server.js ///// var app = express(); app.get('/', function(req, res) { res.status(200).json({ message: 'v1.0' }); }); // test.js…
Justin Young
  • 2,393
  • 3
  • 36
  • 62
0
votes
1 answer

How to mock an import express.js supertest?

I have some controller / route which handles a user signing up: controllers/user.js const User = require('../models/User'); // What I want to mock! ... /** * POST /signup * Create a new local account. */ exports.postSignup = (req, res,…
david_adler
  • 9,690
  • 6
  • 57
  • 97
0
votes
1 answer

Mocha test passes with incorrect data

I have the following test using Mocha, Supertest and Chai: const app = require('../server') const expect = require('chai').should() const request = require('supertest') describe('GET /webhook', function () { context('a verify request from…
tombraider
  • 1,127
  • 1
  • 11
  • 19
0
votes
1 answer

Supertest not working with routes that call .render()

After I add app.use(flash()) to user express-flash, supertest does not work with any route in my app that calls res.render(). The test just times out, it doesn't execute the end or expect callbacks. Static routes and routes that just call res.send…
Marcelo Lazaroni
  • 9,819
  • 3
  • 35
  • 41