-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhello_promise.test.js
More file actions
67 lines (58 loc) · 1.68 KB
/
hello_promise.test.js
File metadata and controls
67 lines (58 loc) · 1.68 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
'use strict';
const test = require('tape');
const { helloPromise } = require('../lib/index.js');
test('success: no options object', async (assert) => {
const result = await helloPromise();
assert.equal(result, 'hello');
assert.end();
});
test('success: empty options object', async (assert) => {
const result = await helloPromise({});
assert.equal(result, 'hello');
assert.end();
});
test('success: options.phrase', async (assert) => {
const result = await helloPromise({ phrase: 'Waka' });
assert.equal(result, 'Waka');
assert.end();
});
test('success: options.multiply', async (assert) => {
const result = await helloPromise({ multiply: 4 });
assert.equal(result, 'hellohellohellohello');
assert.end();
});
test('success: options.phrase and options.multiply', async (assert) => {
const result = await helloPromise({ phrase: 'Waka', multiply: 5 });
assert.equal(result, 'WakaWakaWakaWakaWaka');
assert.end();
});
test('error: invalid options type', async (assert) => {
try {
await helloPromise('not an object');
assert.fail();
} catch (err) {
assert.ok(err);
assert.equal(err.message, 'options must be an object');
}
assert.end();
});
test('error: invalid options.phrase', async (assert) => {
try {
await helloPromise({ phrase: 10 });
assert.fail();
} catch (err) {
assert.ok(err);
assert.equal(err.message, 'options.phrase must be a string');
}
assert.end();
});
test('error: invalid options.multiply', async (assert) => {
try {
await helloPromise({ multiply: 'not a number' });
assert.fail();
} catch (err) {
assert.ok(err);
assert.equal(err.message, 'options.multiply must be a number');
}
assert.end();
});