/
test-custom-assert-methods.js
65 lines (55 loc) · 1.43 KB
/
test-custom-assert-methods.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
59
60
61
62
63
64
65
var http = require('http');
var async = require('async');
exports['test_assert.response'] = function(test, assert) {
var server = http.createServer(function (req, res) {
if (req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'text/plain'});
}
else {
res.writeHead(404, {'Content-Type': 'text/plain'});
}
res.end('hello world');
});
async.series([
function testGet(callback) {
var req = {
'url': '/test',
'method': 'get'
};
assert.response(server, req, function(res) {
assert.equal(res.statusCode, 200);
assert.equal(res.body, 'hello world');
callback();
});
},
function testPost(callback) {
var req = {
'url': '/test',
'method': 'post'
};
assert.response(server, req, function(res) {
assert.equal(res.statusCode, 404);
assert.equal(res.body, 'hello world');
callback();
});
}
],
function(err) {
assert.ifError(err);
test.finish();
});
};
exports['test_other_custom_asserts_functions'] = function(test, assert) {
assert.equal(assert.eql, assert.deepEqual);
assert.isNull(null);
assert.isNotNull(1);
assert.isNotNull(false);
assert.isNotNull(0);
assert.isNotNull(-1);
assert.isDefined(1);
assert.type('a', 'string');
assert.type(function() {}, 'function');
assert.includes([1,2,3], 2);
assert.length([1,2,3], 3);
test.finish();
};