forked from forwardemail/superagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwork-error.js
More file actions
36 lines (32 loc) · 764 Bytes
/
network-error.js
File metadata and controls
36 lines (32 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var request = require('../..')
, express = require('express')
, assert = require('assert')
, net = require('net');
function getFreePort(fn) {
var server = net.createServer();
server.listen(0, function(){
var port = server.address().port;
server.close(function(){
fn(port);
});
});
};
describe('with network error', function(){
before(function(done){
var self = this;
// connecting to a free port
// will trigger a connection refused
getFreePort(function(port){
self.port = port;
done();
});
});
it('should error', function(done) {
request
.get('http://localhost:' + this.port + '/')
.end(function(err, res){
assert(err, 'expected an error');
done();
});
});
});