-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhello_object.test.js
More file actions
49 lines (44 loc) · 1.27 KB
/
hello_object.test.js
File metadata and controls
49 lines (44 loc) · 1.27 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
var test = require('tape');
var module = require('../lib/index.js');
test('success: prints expected string', function(t) {
var H = new module.HelloObject('carol');
var check = H.helloMethod();
t.equal(check, 'carol', 'returned expected string');
t.end();
});
test('error: throws when passing empty string', function(t) {
try {
var H = new module.HelloObject('');
} 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.HelloObject();
} catch(err) {
t.ok(err);
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.HelloObject(24);
} catch(err) {
t.ok(err, 'expected error');
t.ok(err.message, 'A string was expected', 'expected error message');
t.end();
}
});
test('error: handles missing arg', function(t) {
try {
var H = new module.HelloObject();
} catch (err) {
t.ok(err, 'expected error');
t.ok(err.message, 'must provide string arg', 'expected error message');
t.end();
}
});