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

Diacritic chars encoding in API requests

I have one question about encoding diacritic chars in API request. I can send via postman request GET /rest/city?query=Poznań, response is correct, in server logs city?query=Poznań is changed to city?query=Pozna%C5%84. Also I have API test written…
mtmx
  • 827
  • 1
  • 10
  • 31
0
votes
1 answer

How to correctly unit test Express 4 server with Jest

Trying to get a better understanding of it, I am testing this simple Express server (v 4 ) setup code : server.js import express from 'express'; import router from './routes'; const app = express(); app.use(router); const server = app.listen(3000,…
user762579
0
votes
1 answer

How does request(app).del()/.delete() work for Mocha/Supertest?

I have a test for Mocha, using expect and supertest, that works just fine. But I don't understand how it works. I'm using express as my server, along with mongodb and mongoose. I understand how testing for .get() would work, that makes perfect…
0
votes
1 answer

Mocha skipping over test

beginner here (Node, JS) trying to understand why Mocha is skipping over my test. I realise I am using using request / supertest libraries sub-optimally, but I just want to understand why, when it hit the 'it' in debugging, it simply skips to the…
Steerpike
  • 1,712
  • 6
  • 38
  • 71
0
votes
1 answer

Using Supertest with Mocha with a consistent base api url

I'm trying to use Supertest for the first time against an actual API, not an express app or mock. My understanding is that this syntax should work: const request = require('supertest')('https://my-api.com'); describe('Obtain a new customer',…
Steerpike
  • 1,712
  • 6
  • 38
  • 71
0
votes
1 answer

Cleaning out test database before starting integration test in jest supertest

I have this code in my user.test.js : const request = require('supertest'); let server ; const {User} = require('./../../models/user'); describe('/users', () => { beforeEach(() => server = require('./../../index')); afterEach(() =>…
sriram hegde
  • 2,301
  • 5
  • 29
  • 43
0
votes
1 answer

Supertest async callback was not invoked

I'm getting the following issue by trying to test a minimalist example with supertest (and jest): Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout. Please note that this is not a duplicate of the…
Juicy
  • 11,840
  • 35
  • 123
  • 212
0
votes
1 answer

MochaJS: Rejected promises not triggering a failed test

I'm using async-await syntax with Mocha and Supertest. This is my problematic test: it('Test POST/friends route: should add a friendship', async function () { const lastFriendship = await models.Friendship.findAll({limit: 1,where:…
i.brod
  • 3,993
  • 11
  • 38
  • 74
0
votes
2 answers

Stubing a class call from another function

I have 2 files controller.js and entity.js which interact with each other. I am testing controller.js, and it creates an instance of entity.js (class) and use one of its functions. How can I stub/mock/spy the call and the return of that…
Menticolcito
  • 769
  • 1
  • 5
  • 11
0
votes
0 answers

Testing failed with Mocha, Chai and Supertest (NodeJS), retrieving data from mongodb

It is my first time testing the routes in node js and I'm using mocha, supertest and chai. Here is my server.js file: const express = require('express'); const app = express(); const path = require('path'); const http =…
Shad
  • 63
  • 1
  • 1
  • 10
0
votes
1 answer

TypeError: Cannot read property 'close' of undefined

I'm new to nodejs and koa. There is this existing Koa app (running and working fine with no problem) that I am trying to write a test code using Jest. I have searched sample tests that can be possibly applied to this case but to no avail. Now, I…
tatskie
  • 405
  • 1
  • 7
  • 16
0
votes
0 answers

Can I mock an individual function that is imported into the module I import with jest?

I have written a nodeJS module mymodule.js that imports the sqlite module. I now want to write some jest tests so I imported my module.js into my jest test script but want to mock some of the sqlite functions such as get() in a couple of tests. All…
Mark Tyers
  • 2,961
  • 4
  • 29
  • 52
0
votes
2 answers

Testing Mocha/supertest/expect MEAN-stack HTTP Request 4 seconds delay done

I am testing a HTTP Request in MEAN-Stack with Mocha/supertest/expect library, that takes 4 seconds to return: it('should return product data', (done) => { request(app) .get('/P/Product') .expect(200) .expect((res) => { …
MMMM
  • 3,320
  • 8
  • 43
  • 80
0
votes
0 answers

Uncaught AssertionError: expected {} to equal 'testing'

I'm not sure why it's saying the object is empty. This is my testing block of code. describe("POST /users", () => { let body = { name: "testing", email: "testing@testing.com", password: 123456 }; it("Creates a new user", done =>…
Yama
  • 401
  • 1
  • 8
  • 22
0
votes
1 answer

Is it possible to run mocha test suite from node endpoint?

Our team has built an API for providing internal web services to our organization. I have built a mocha test suite for testing the code base, and am currently running it via the CLI. We have a corporate monitoring service that regularly tests a…
208_man
  • 1,440
  • 3
  • 28
  • 59