-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis.spec.js
More file actions
45 lines (35 loc) · 1016 Bytes
/
is.spec.js
File metadata and controls
45 lines (35 loc) · 1016 Bytes
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
import is from '../lib/utils/is'
const func = () => {}
const array = []
const string = ''
const obj = {}
const number = 1
const neil = null
const undef = undefined
const typeList = [func, array, obj, string, number, neil, undef]
function testEach(func, targets, toBe) {
targets.forEach(target => expect(func(target)).toBe(toBe))
}
function byPass(func, targets, except) {
const truthy = targets.filter(t => t === except)
const falsy = targets.filter(t => t !== except)
testEach(func, truthy, true)
testEach(func, falsy, false)
}
describe('is', () => {
it('should be function', () => {
byPass(is.function, typeList, func);
})
it('should be number', () => {
byPass(is.number, typeList, number);
})
it('should be object', () => {
byPass(is.object, typeList, obj);
})
it('should be array', () => {
byPass(is.array, typeList, array);
})
it('should be string', () => {
byPass(is.string, typeList, string);
})
})