-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_reply_with_error.js
56 lines (46 loc) · 1.13 KB
/
test_reply_with_error.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
// Tests for `.replyWithError()`.
const http = require('http')
const { expect } = require('chai')
const nock = require('..')
describe('`replyWithError()`', () => {
it('returns an error through the request', done => {
const scope = nock('https://example.test')
.post('/echo')
.replyWithError('Service not found')
const req = http.request({
host: 'example.test',
method: 'POST',
path: '/echo',
port: 80,
})
req.on('error', e => {
expect(e)
.to.be.an.instanceof(Error)
.and.include({ message: 'Service not found' })
scope.done()
done()
})
req.end()
})
it('allows json response', done => {
const scope = nock('https://example.test')
.post('/echo')
.replyWithError({ message: 'Service not found', code: 'test' })
const req = http.request({
host: 'example.test',
method: 'POST',
path: '/echo',
port: 80,
})
req.on('error', e => {
expect(e).to.deep.equal({
message: 'Service not found',
code: 'test',
})
scope.done()
done()
})
req.end()
})
})