-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAllMenuItems.test.js
More file actions
53 lines (48 loc) · 911 Bytes
/
getAllMenuItems.test.js
File metadata and controls
53 lines (48 loc) · 911 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
46
47
48
49
50
51
52
53
/**
* @jest-environment node
*/
import "regenerator-runtime/runtime.js";
import getAllMenuItems from './getAllMenuItems'
const db = {
1: [2,4],
2: [3],
3: [],
4: [],
}
const fetch = url => Promise.resolve(
JSON.stringify({
id: url.split('=')[1],
name: 'John Doe',
label: 'Main Item',
children: db[url.split('=')[1]]
})
)
const expectedResponse = {
id: '1',
name: 'John Doe',
label: 'Main Item',
children: [
{
id: '2',
name: 'John Doe',
label: 'Main Item',
children: [
{
id: '3',
name: 'John Doe',
label: 'Main Item',
children: []
}
]
},
{
id: '4',
name: 'John Doe',
label: 'Main Item',
children: []
}
]
}
test('getAllMenuItems returns the correct JSON', async () => {
expect(await getAllMenuItems(fetch)(1)).toEqual(expectedResponse)
});