-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
47 lines (33 loc) · 900 Bytes
/
index.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
'use strict';
var test = require( 'ava' )
var uniqPort = require( '.' )
var correctValues = {
'uniq-port': 54115,
'your-unique-app-name': 65293,
'uniq': 56645,
'port': 49619,
'': 49152
}
var incorrectValues = [
{},
[],
null,
undefined
]
Object.keys( correctValues ).forEach( function ( name ) {
test( 'generates port for `' + name + '`', function ( t ) {
var expected = correctValues[ name ];
t.is( uniqPort( name ), expected );
})
} )
test( 'generates port for number (31337)', function ( t ) {
t.is( uniqPort( 31337 ), 50433 );
})
incorrectValues.forEach( function ( type ) {
test( 'throws on ' + JSON.stringify( type ), function ( t ) {
var error = t.throws( function () {
uniqPort( type )
}, TypeError )
t.is( error.message, '`name` must be a string or a number' );
} )
} )