forked from brianleroux/tiny-json-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-get.js
58 lines (54 loc) · 1.23 KB
/
test-get.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
57
58
var test = require('tape')
var tiny = require('./')
test('env', t=> {
t.plan(5)
t.ok(tiny, 'got a tiny')
t.ok(tiny.get, 'got a tiny.get')
t.ok(tiny.post, 'got a tiny.post')
t.ok(tiny.put, 'got a tiny.put')
t.ok(tiny.del, 'got a tiny.delete')
console.log(tiny)
})
test('can get a url', t=> {
t.plan(3)
var url = 'https://brian.io'
tiny.get({url}, function __got(err, result) {
if (err) {
t.fail(err.statusCode, 'failed to get')
console.log(err)
}
else {
t.ok(result, 'got a result')
t.ok(result.headers, 'got headers')
t.ok(result.body, 'got body')
console.log(result)
}
})
})
test('can get json', t=> {
t.plan(2)
var url = 'https://api.github.com/'
tiny.get({url}, function __json(err, result) {
if (err) {
t.fail(err)
}
else {
t.ok(result, 'got a result')
t.equal(typeof result.body, 'object', 'body is an object')
console.log(err, result)
}
})
})
test('get fails gracefully', t=> {
t.plan(1)
var url = 'http://nop333.ca'
tiny.get({url}, function __ruhroh(err, result) {
if (err) {
t.ok(err, 'got err as expected')
console.log(err)
}
else {
t.fail(result, 'should not succeed')
}
})
})