forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-toJSON.js
45 lines (36 loc) · 941 Bytes
/
test-toJSON.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
'use strict'
var request = require('../index')
var http = require('http')
var tape = require('tape')
var s = http.createServer(function (req, resp) {
resp.statusCode = 200
resp.end('asdf')
})
tape('setup', function (t) {
s.listen(0, function () {
s.url = 'http://localhost:' + this.address().port
t.end()
})
})
tape('request().toJSON()', function (t) {
var r = request({
url: s.url,
headers: { foo: 'bar' }
}, function (err, res) {
var jsonR = JSON.parse(JSON.stringify(r))
var jsonRes = JSON.parse(JSON.stringify(res))
t.equal(err, null)
t.equal(jsonR.uri.href, r.uri.href)
t.equal(jsonR.method, r.method)
t.equal(jsonR.headers.foo, r.headers.foo)
t.equal(jsonRes.statusCode, res.statusCode)
t.equal(jsonRes.body, res.body)
t.equal(jsonRes.headers.date, res.headers.date)
t.end()
})
})
tape('cleanup', function (t) {
s.close(function () {
t.end()
})
})