-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
166 lines (149 loc) · 3.67 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var test = require('tape');
var logic = require('./logic');
var singleTodo = {
description: 'sprinkle coriander',
done: true,
}
// general working tests
test('Tape runs okay', function(t) {
t.equal(1, 1, 'One should equal one');
t.end(); // this tells tape we've finished
});
test('Todos array contains only objects', function(t) {
var todosObject = [{}, {}];
var actual = (!Array.isArray(todosObject[0]) && typeof todosObject[0] === 'object');
var expected = true;
t.deepEqual(actual, expected, 'Todos array should only contain objects');
t.end();
});
// addTodo tests
test('addTodo function gives an id to the newTodo', function(t) {
var actual = logic.addTodo([], singleTodo)[0].hasOwnProperty("id");
var expected = true;
t.equal(actual, expected, 'newTodo should have an id key');
t.end();
});
test('newTodo is added to end of todos', function(t) {
var todoArray = [{
id: 0,
description: 'smash avocados',
done: true,
},
{
id: 1,
description: 'squeeze lemon',
done: false,
}
]
var newArray = [{
id: 0,
description: 'smash avocados',
done: true,
},
{
id: 1,
description: 'squeeze lemon',
done: false,
},
{
id: 2,
description: 'sprinkle coriander',
done: true,
}
]
var actual = logic.addTodo(todoArray, singleTodo);
var expected = newArray;
t.deepEqual(actual, expected, 'newTodo should be added to end of todos in new array');
t.end();
})
test('input arguments are unchanged', function(t) {
var expected = [];
logic.addTodo(expected, singleTodo);
t.deepEqual([], expected, 'input arguments should not change');
t.end();
})
test('addTodo returns a new array', function(t) {
var todoArray = [{
id: 0,
description: 'smash avocados',
done: true,
},
{
id: 1,
description: 'squeeze lemon',
done: false,
}
]
var actual = logic.addTodo(todoArray, singleTodo).length !== todoArray.length;
var expected = true;
t.equal(actual, expected, 'addTodo should return a new array');
t.end();
})
// deleteTodo tests
test('deleteTodo should remove object at index "iDToDelete" from array "todos"', function(t) {
var actual = logic.deleteTodo([{id: 0},{id: 1},{id: 2},{id: 3}], 3);
var expected = [{id: 0},{id: 1},{id: 2}];
t.deepEqual(actual, expected, 'deleteTodo should remove object at index "iDToDelete" from array "todos"');
t.end();
});
test('Todos is left unchanged by the function', function(t) {
var originalTodos = [{
0: 0
}, {
1: 1
}];
var actual = logic.deleteTodo(originalTodos, 0);
var expected = [{
0: 0
}, {
1: 1
}];
t.deepEqual(originalTodos, expected, 'Todos should be left unchanged by the function');
t.end();
});
// markTodo tests
test('markTodo toggles done value', function(t) {
var unmarkedTodo = [{
id: 0,
description: 'add chilli',
done: false,
},
{
id: 1,
description: 'onion',
done: true,
}
]
var markedTodo = [{
id: 0,
description: 'add chilli',
done: true,
},
{
id: 1,
description: 'onion',
done: true,
}
]
var actual = logic.markTodo(unmarkedTodo, 0);
var expected = markedTodo;
t.deepEqual(actual, expected, 'markTodo should toggle done value');
t.end();
})
test('Todos is left unchanged by the function', function(t) {
var actual = [{
id: 0,
description: 'add chilli',
done: false,
},
{
id: 1,
description: 'onion',
done: true,
}
]
var expected = actual;
logic.markTodo(actual, 0);
t.deepEqual(actual, expected, 'Todos should be left unchanged by the function');
t.end();
});