-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
54 lines (49 loc) · 922 Bytes
/
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
import test from 'ava'
import objSeach from './index'
import type from 'type-detect'
const obj = {
'name': 'Product',
'properties':
{
'id':
{
'type': 'number',
'description': 'Product identifier',
'required': true
},
'name':
{
'description': 'Name of the product',
'type': 'string',
'required': true
},
'price':
{
'type': 'number',
'minimum': 0,
'required': true
},
'tags':
{
'type': 'array',
'items':
{
'type': 'string'
}
}
}
}
test('is a function', t => {
t.true(type(objSeach) === 'function')
})
test('match a prop', t => {
t.deepEqual(objSeach(obj, 'name'), 'Product')
})
test('match a nested prop', t => {
const prop = {
'type': 'number',
'description': 'Product identifier',
'required': true
}
t.deepEqual(objSeach(obj, 'properties.id'), prop)
})