forked from ProtoSchool/protoschool.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasserts.js
More file actions
61 lines (53 loc) · 1.83 KB
/
Copy pathasserts.js
File metadata and controls
61 lines (53 loc) · 1.83 KB
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
// Used with generateTutorial
function assertNewTutorial ({ context, result, expected }) {
expect(result).toBeInstanceOf(Object)
expect(result.id).toBe(context.lastTutorialId + 1)
expect(result.title).toBe(expected.title)
expect(result.project.id).toBe(expected.project)
expect(result.description).toBe(expected.description)
if (result.lessons.length) {
result.lessons.forEach((lesson, i) => {
const id = i + 1
expect(lesson).toMatchObject({
id,
formattedId: (id).toString().padStart(2, 0),
title: `Lesson ${id}`,
...expected.lessons[i]
})
})
} else {
expect(result.lessons).toHaveLength(0)
}
if (result.resources) {
for (let i in result.resources) {
expect(result.resources[i]).toMatchObject(expected.resources[i])
}
} else {
expect(result.resources).toHaveLength(0)
}
}
// Used with generateLesson
function assertNewLesson ({ result, expected }) {
expect(result).toBeInstanceOf(Object)
expect(result.id).toBe(expected.tutorial.id)
expect(result.title).toBe(expected.tutorial.title)
expect(result.project).toMatchObject(expected.tutorial.project)
expect(result.description).toBe(expected.tutorial.description)
expect(result.lessons).toHaveLength(1)
expect(result.lessons[0]).toMatchObject(expected.lesson)
}
// Used with generateResource
function assertNewResource ({ result, expected }) {
expect(result).toBeInstanceOf(Object)
expect(result.id).toBe(expected.tutorial.id)
expect(result.title).toBe(expected.tutorial.title)
expect(result.project).toMatchObject(expected.tutorial.project)
expect(result.description).toBe(expected.tutorial.description)
expect(result.resources).toHaveLength(1)
expect(result.resources[0]).toMatchObject(expected.resource)
}
module.exports = {
assertNewTutorial,
assertNewLesson,
assertNewResource
}