-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
66 lines (53 loc) · 1.7 KB
/
test.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
66
'use strict';
const arrayToSentence = require('.');
const test = require('tape');
test('arrayToSentence()', t => {
t.equal(
arrayToSentence(['foo', true, 1, null]),
'foo, true, 1 and null',
'should create a human-readable string from more than three elements.'
);
const options = {};
t.equal(
arrayToSentence(['foo', true], options),
'foo and true',
'should create a human-readable string from two elements.'
);
t.deepEqual(
options,
{},
'should treat the passed options object immutable way.'
);
t.equal(
arrayToSentence(['foo'], null),
'foo',
'should create a human-readable string from an elements.'
);
t.equal(arrayToSentence([]), '', 'should return an empty string if the array is empty.');
t.equal(
arrayToSentence(['a', 'c', 'e'], {separator: 'b', lastSeparator: 'd'}),
'abcde',
'should change the separator words in response to the options.'
);
t.throws(
() => arrayToSentence(),
/TypeError.*Expected an array, but got a non-array value undefined\./,
'should throw a type error when it takes no arguments.'
);
t.throws(
() => arrayToSentence('foo'),
/TypeError.*Expected an array, but got a non-array value foo\./,
'should throw a type error when the first argument is not an array.'
);
t.throws(
() => arrayToSentence([], {separator: 1}),
/TypeError.*Expected `separator` option to be a string, but got a non-string value 1\./,
'should throw a type error when `separator` option is not a string.'
);
t.throws(
() => arrayToSentence([], {lastSeparator: NaN}),
/TypeError.*Expected `lastSeparator` option to be a string, but got a non-string value NaN\./,
'should throw a type error when `lastSeparator` option is not a string.'
);
t.end();
});