Questions tagged [chai-http]

102 questions
11
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
  • 2,782
  • 5
  • 27
  • 48
6
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,286
  • 15
  • 26
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
  • 6
5
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
  • 5,653
  • 13
  • 48
  • 89
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,136
  • 4
  • 20
  • 57
5
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
  • 61
  • 8
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…
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 =…
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
  • 695
  • 1
  • 9
  • 17
3
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
  • 157
  • 2
  • 10
3
votes
1 answer

Mocha chai-http response always returns null

I'm testing a server response in Node.js via mocha chai-http. The response I get is always null. However, When I run requests regularly without mocha test runner, Everything is fine. This is the sever code: var Babble = { messages: new Array() ,…
Shaked
  • 165
  • 1
  • 9
3
votes
2 answers

How do I check when multiple chai-http requests are really done in a mocha before block?

I'm using a before block in a set of mocha unit tests and within them I'm iterating over a set of calls to get information from a REST API. I'm using chai-http to do this. However I am running into the problem that the done() method is being…
JSDevGuy
  • 97
  • 1
  • 8
2
votes
1 answer

Mocha Chai check if Json response contains specific property

I'm creating API test which checks that the response contains specific key "textId" in structure: it('TC-4 /rest/passwords/ should change "password"', function() { return chai.request(serverurl) .post('/rest/passwords/') …
destr
  • 25
  • 5
2
votes
3 answers

Typescript, Express, Mocha & Chai Error while testing

I made my first server using express in typescript and it perfectly works import app from './Server' const server = app.listen(8080, '0.0.0.0', () => { console.log("Server is listening on standard port 80..."); }); export default server; Now…
2
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
  • 113
  • 1
  • 10
1
2 3 4 5 6 7