1

I want write a test in mocha for how a timeout is handled.

I can set up a server that will never answer using netcat nc -kl 8080 (thanks https://stackoverflow.com/a/37465639/5203563).

However, since I already run an express server for all my other test endpoints inside mocha, it would be great if I could achieve the same thing with an express endpoint.

Does anybody know if that is possible?

Community
  • 1
  • 1
Alex028502
  • 3,486
  • 2
  • 23
  • 50

2 Answers2

3

Just don't return a response

 var app = require('express')();

 app.get('/fail', function(req, res) {
   // does nothing
 });

 app.listen(8080);
R. Gulbrandsen
  • 3,648
  • 1
  • 22
  • 35
1

Don't return the response from the route.

app.get('/', function(req, res) {});
Mukesh Sharma
  • 8,914
  • 8
  • 38
  • 55