-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
82 lines (75 loc) · 1.45 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var test = require('tape')
var hs = require('./')
test('switch should exist', function(t) {
t.plan(1)
t.ok(hs)
})
test('should accept minimal arguments', function(t) {
t.plan(1)
t.ok(hs([]))
})
test('should call defaultCallback', function(t) {
t.plan(1)
var hash = hs({
'yolo': function() {
return 'YOLO'
}
},
function() {
return 'FWEE'
}
)
t.equal(hash('fwee'), 'FWEE')
})
test('should call action callback', function(t) {
t.plan(1)
var hash = hs({
'yolo': function() {
return 'YOLO'
}
},
function() {
return 'FWEE'
}
)
t.equal(hash('yolo'), 'YOLO')
})
test('should register multipe action callbacks', function(t) {
t.plan(5)
var hash = hs({
1: function one () {
return 1
},
'yolo': function() {
return 'YOLO'
},
'enzo': function() {
return 'SUP'
},
'lazlo': function() {
return 'DUDE'
}
},
function() {
return 'FWEE'
}
)
t.equal(hash(1), 1)
t.equal(hash('yolo'), 'YOLO')
t.equal(hash('enzo'), 'SUP')
t.equal(hash('lazlo'), 'DUDE')
t.equal(hash('foo'), 'FWEE')
})
test('should pass function arguments to callback', function(t) {
t.plan(1)
var hash = hs({
'yolo': function(arg1, arg2) {
return 'YOLO' + ' ' + arg1 + ' ' + arg2
}
},
function() {
return 'FWEE'
}
)
t.equal(hash('yolo', 'NOLO', 'HOLO'), 'YOLO NOLO HOLO')
})