-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
146 lines (145 loc) · 3.17 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
let test = require("tape");
let logic = require("./logic");
let testArr = [
{
id: -3,
description: "first todo",
done: false
},
{
id: -2,
description: "second todo",
done: false
},
{
id: -1,
description: "third todo",
done: false
}
];
let testObj = {
description: "test todo"
};
test("Example test", function(t) {
t.pass();
t.end();
});
test("check that addToDo accepts input", function(t) {
const actual = typeof logic.addTodo(testArr, testObj);
const expected = "object";
t.deepEqual(actual, expected, "should accept input and return an array");
t.end();
});
test("check that todos hasn't changed", t => {
const actual = logic.addTodo(testArr, testObj).slice(0, testArr.length);
const expected = testArr;
t.deepEqual(actual, expected, "should not change the original todos array");
t.end();
});
test("check that it returns todos array plus new todo", t => {
const actual = logic.addTodo(testArr, testObj);
const expected = [
{
id: -3,
description: "first todo",
done: false
},
{
id: -2,
description: "second todo",
done: false
},
{
id: -1,
description: "third todo",
done: false
},
{
id: 1,
description: "test todo",
done: false
}
];
t.deepEqual(actual, expected, "returns todo array plus new todo");
t.end();
});
test("check that newTodo has an id", t => {
const actual = logic
.addTodo(testArr, testObj)
.pop()
.hasOwnProperty("id");
const expected = true;
t.deepEqual(actual, expected, "should add a property of id to newTodo");
t.end();
});
test("check that markTodo accepts input and returns an array", t => {
const testId = -1;
const actual = typeof logic.addTodo(testArr, testId);
const expected = "object";
t.deepEqual(actual, expected, "should accept input and return an array");
t.end();
});
test("check that the 'done' property is toggled for the specified ID", t => {
const testId = -1;
const actual = logic.markTodo(testArr, testId);
const expected = [
{
id: -3,
description: "first todo",
done: false
},
{
id: -2,
description: "second todo",
done: false
},
{
id: -1,
description: "third todo",
done: true
}
];
t.deepEqual(actual, expected, "should toggle done property");
t.end();
});
//deleteToDo tests
test("leave the input argument todos unchanged", t => {
const actual = logic.deleteTodo(testArr);
const expected = [
{
id: -3,
description: "first todo",
done: false
},
{
id: -2,
description: "second todo",
done: false
},
{
id: -1,
description: "third todo",
done: false
}
];
t.deepEqual(actual, expected, "input is unchanged");
t.end();
});
test("Check if the idToDelete has been deleted", t => {
const testID = -2;
const actual = logic.deleteTodo(testArr, testID);
const expected = [
{
id: -3,
description: "first todo",
done: false
},
{
id: -1,
description: "third todo",
done: false
}
];
t.deepEqual(actual, expected, "element has been deleted");
t.end();
});