-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhello_object_async.test.js
More file actions
109 lines (98 loc) · 3.29 KB
/
hello_object_async.test.js
File metadata and controls
109 lines (98 loc) · 3.29 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var test = require('tape');
var module = require('../lib/index.js');
test('success: prints expected string via custom constructor', function(t) {
var H = new module.HelloObjectAsync('carol');
H.helloAsync({ louder: false }, function(err, result) {
if (err) throw err;
t.equal(result, '...threads are busy async bees...hello carol');
t.end();
});
});
test('success: prints loud busy world', function(t) {
var H = new module.HelloObjectAsync('world');
H.helloAsync({ louder: true }, function(err, result) {
if (err) throw err;
t.equal(result, '...threads are busy async bees...hello world!!!!');
t.end();
});
});
test('success: return buffer busy world', function(t) {
var H = new module.HelloObjectAsync('world');
H.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: throws when passing empty string', function(t) {
try {
var H = new module.HelloObjectAsync('');
} catch(err) {
t.ok(err, 'expected error');
t.equal(err.message, 'arg must be a non-empty string', 'expected error message')
t.end();
}
});
test('error: throws when missing "new"', function(t) {
try {
var H = module.HelloObjectAsync('world');
} catch(err) {
t.ok(err, 'expected error');
t.equal(err.message, 'Class constructors cannot be invoked without \'new\'', 'expected error message')
t.end();
}
});
test('error: handles non-string arg within constructor', function(t) {
try {
var H = new module.HelloObjectAsync(24);
} catch(err) {
console.log(err.message);
t.equal(err.message, 'String expected', 'expected error message');
t.end();
}
});
test('error: handles invalid louder value', function(t) {
var H = new module.HelloObjectAsync('world');
H.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) {
var H = new module.HelloObjectAsync('world');
H.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) {
var H = new module.HelloObjectAsync('world');
H.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) {
var H = new module.HelloObjectAsync('world');
try {
H.helloAsync({ louder: false}, {});
} 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();
}
});
test('error: handles missing arg', function(t) {
try {
var H = new module.HelloObjectAsync();
} catch (err) {
t.ok(err, 'expected error');
t.equal(err.message, 'String expected', 'expected error message');
t.end();
}
});