blob: defeda32454a0c8fccbaab631bcee258849bb747 (
plain)
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
|
'use strict'
const { test } = require('tap')
const { Client } = require('..')
const net = require('net')
test('connect-connectionError', t => {
t.plan(2)
const client = new Client('http://localhost:9000')
t.teardown(client.close.bind(client))
client.once('connectionError', () => {
t.pass()
})
const _err = new Error('kaboom')
net.connect = function (options) {
const socket = new net.Socket(options)
setImmediate(() => {
socket.destroy(_err)
})
return socket
}
client.request({
path: '/',
method: 'GET'
}, (err) => {
t.equal(err, _err)
})
})
|