-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems.test.js
More file actions
70 lines (63 loc) · 1.94 KB
/
problems.test.js
File metadata and controls
70 lines (63 loc) · 1.94 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
62
63
64
65
66
67
68
69
70
// PROBLEMS-TEST
// --------------------------------------------------------------------------------
// Test that the problems repo has imported properly,
// and that it's in the format we expect
import problems from 'pjs-problems'
import is from 'is'
test('problems must be importable', () => {
expect(problems).toBeDefined()
})
test('problems must be an object', () => {
expect(is.object(problems)).toBe(true)
})
test('problems direct children attribute values must be non-empty arrays', () => {
Object.entries(problems).map(item => {
// is valid array
expect(is.array(item[1])).toBe(true)
// has more than zero items
expect(item[1].length).toBeGreaterThan(0)
})
})
test('problems must each have the required attributes', () => {
Object.entries(problems).map(item => {
item[1].forEach(problem => {
// name
expect(problem.name).toBeTruthy()
expect(is.string(problem.name)).toBe(true)
// prompt
expect(problem.prompt).toBeTruthy()
expect(is.string(problem.prompt)).toBe(true)
// given
expect(problem.given).toBeTruthy()
expect(is.string(problem.given)).toBe(true)
// tests
expect(problem.tests).toBeTruthy()
expect(is.array(problem.tests)).toBe(true)
})
})
})
test('problems tests must non-empty array', () => {
Object.entries(problems).map(item => {
item[1].forEach(problem => {
// tests
// is array
expect(is.array(problem.tests)).toBe(true)
// non-empty
expect(problem.tests.length).toBeGreaterThan(0)
})
})
})
test('problems tests must each have the required attributes', () => {
Object.entries(problems).map(item => {
item[1].forEach(problem => {
problem.tests.forEach(test => {
// name
expect(test.name).toBeTruthy()
expect(is.string(test.name)).toBe(true)
// test
expect(test.test).toBeTruthy()
expect(is.string(test.test)).toBe(true)
})
})
})
})