For questions regarding integration testing used with chai-http library. It is an add-on plugin for chai library to be used in integration testing.
Questions tagged [chai-http]
114 questions
12
votes
1 answer
chai-http not exiting after running tests
I ran into a problem where my mocha tests were not finishing after running with chai-http. Mocha just hangs after the tests and eventually runs into a timeout (at least on my CI).

El Mac
- 3,256
- 7
- 38
- 58
8
votes
1 answer
Set accepted CA list and ignore SSL errors with chai-http
I'm trying to write unit tests for my node code with chai/chai-http. Everything was working fine until I switched my server to an HTTPS server, but because my certificate is signed by an internal company root and the common name of the certificate…

Jared
- 91
- 1
- 8
7
votes
0 answers
How to do HTTPS GET with client certificate in Axios
How to perform get request with client certificate like below using chai-http?
curl -k --key [key_path] --cert [cert-path]:secret 'https://127.0.0.1/url'
The following code returns error:
Error: error:0906A068:PEM routines:PEM_do_header:bad…

rok
- 9,403
- 17
- 70
- 126
7
votes
2 answers
How to correctly close express server between tests using mocha and chai
I am looking for a correct way to completely reset my express server between tests! It seems that this is not just a problem for me, many other users have asked the same question,
and many blog posts had been written on the argument. The proposed…

Elia
- 1,417
- 1
- 18
- 28
5
votes
1 answer
Stubbing Out Middleware
I'm trying to use Sinon to stub out some custom middleware in an express route but it's not working as I expect it to. I expect it to not log "I am authenticating..." and instead log "Stubbed" to the console. It looks like sinon is not stubbing out…

akl47
- 81
- 7
5
votes
1 answer
Testing GraphQL API
I'm testing my GraphQL API, but I would like to clean it up a little bit. It's worth noting I'm using chai-http for the network requests. Here's what I'm currently doing (which works):
let createUser = (()=> {
return new Promise((resolve, reject)…

Thomas
- 2,356
- 7
- 23
- 59
4
votes
1 answer
How to send context parameter in unit test to a firebase functions running on the functions emulator
I manage to start the firebase emulators and load a cloud function. Now I want to write a test.
PROBLEM I use chai-http to call the function in the emulator but I do not succeed in sending a context to the function.
when calling the function using…

koma
- 6,486
- 2
- 27
- 53
4
votes
1 answer
Chai-Http always returns 404 error code
So basically, I have this rest api written off Node and Express using Typescript. I am trying to use chai, chai-http and mocha to get the api endpoints tested. But whichever test runs, I always get a 404 not found. Here is my code:
app.ts:
let…

Killer Beast
- 177
- 1
- 3
- 11
4
votes
1 answer
How to TDD koa2 with mocha?
I'm trying to get a TDD workflow going with koa2/mocha/chai/chai-http but my problem is that when I run the tests the koa2 server keeps running after the tests are finished. So that I have to Ctrl+C (kill) it every time.
Can anyone tell me how to…

Johannes Frey
- 41
- 2
4
votes
1 answer
How to use Chai-HTTP with Sinon?
Here is the route I want to test:
app.post('/api/user', (req, res) => {
dbService.replaceUserOnDuplicate(req.body, function returnResponse(insertedId) {
if (insertedId === 0 || insertedId === req.body.id) {
…

Minh Lu
- 79
- 4
4
votes
0 answers
It's possible to write api rest automated test using webdriverIO and chai-http?
I'm trying to use webdriverIO to make automatic test over an API rest without any result, also try with chai and chai-http using webdriverIO, but nothing yet. Any clue?
This is something I wrote:
var chai = require('chai');
var chaiHttp =…

Salvador Salvatierra
- 51
- 1
- 5
4
votes
2 answers
chai-http and async.each, throwing "Timeout of 2000ms exceeded..."
I have a simple test with chai-http, in which I try to test several URLs using async.each, but when the request takes more than 2 seconds, then I got the error.
it("it should GET the required images", (done) => {
async.each(get_data,…

Laerion
- 805
- 2
- 13
- 18
3
votes
0 answers
Testing express.Router() with chai gives "TypeError: res.send is not a function"?
I have a controller/route file like this..
const express = require('express');
const pService = require('../../services/parameter/service');
let router = express.Router()
router.get('/valuebyobject/:main/:sub?', pService.getValue);
and the…

Hsn
- 1,168
- 2
- 16
- 39
3
votes
0 answers
Query params using chai-http request are not assigned to _query object
I am writing unit tests for an ts node api.
I am using the chai-http to instantiate/mock requests, however using the .query option referred to in the docs here does not seem to actually add my query params to the request objects qs parameter.
const…

Rogan88
- 111
- 2
- 14
3
votes
1 answer
How to test an API that calls another external API in node
I'm using mocha, chai, and chai-http to test my simple API that routes calls from Slack to Habitica, integrating these two services.
I'm trying to start by creating tests, but I'm facing this issue: when I call my API, the code returns before the…

André Maldonado
- 123
- 1
- 10