-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhello_async.test.js
More file actions
62 lines (55 loc) · 1.94 KB
/
hello_async.test.js
File metadata and controls
62 lines (55 loc) · 1.94 KB
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
var test = require('tape');
var module = require('../lib/index.js');
test('success: prints loud busy world', function(t) {
module.helloAsync({ louder: true }, function(err, result) {
if (err) throw err;
t.equal(result, '...threads are busy async bees...hello world!!!!');
t.end();
});
});
test('success: prints regular busy world', function(t) {
module.helloAsync({ louder: false }, function(err, result) {
if (err) throw err;
t.equal(result, '...threads are busy async bees...hello world');
t.end();
});
});
test('success: buffer regular busy world', function(t) {
module.helloAsync({ buffer: true }, function(err, result) {
if (err) throw err;
t.equal(result.length, 44);
t.equal(typeof(result), 'object');
t.equal(result.toString(), '...threads are busy async bees...hello world');
t.end();
});
});
test('error: handles invalid louder value', function(t) {
module.helloAsync({ louder: 'oops' }, function(err, result) {
t.ok(err, 'expected error');
t.ok(err.message.indexOf('option \'louder\' must be a boolean') > -1, 'expected error message');
t.end();
});
});
test('error: handles invalid buffer value', function(t) {
module.helloAsync({ buffer: 'oops' }, function(err, result) {
t.ok(err, 'expected error');
t.ok(err.message.indexOf('option \'buffer\' must be a boolean') > -1, 'expected error message');
t.end();
});
});
test('error: handles invalid options value', function(t) {
module.helloAsync('oops', function(err, result) {
t.ok(err, 'expected error');
t.ok(err.message.indexOf('first arg \'options\' must be an object') > -1, 'expected error message');
t.end();
});
});
test('error: handles missing callback', function(t) {
try {
module.helloAsync({ louder: 'oops' }, {});
} catch (err) {
t.ok(err, 'expected error');
t.ok(err.message.indexOf('second arg \'callback\' must be a function') > -1, 'expected error message');
t.end();
}
});