forked from fac-17/ABCD-week2-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
96 lines (77 loc) · 3.05 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
var test = require('tape');
var logic = require('./logic');
var todos = [
{id: 0, description: 'make tea', done: false},
{id: 1, description: 'make eggs', done: true},
]
var newTodo = { description: 'make smoothie' };
/* TESTS RELATING TO THE addTodo FUNCTION */
test('addTodo returns an object', function(t) {
const actual = typeof logic.addTodo(todos, newTodo);
const expected = "object";
t.equal(actual, expected, 'addTodo returns an object');
t.end();
});
test('original todo\'s stay the same', function(t) {
const actual = todos;
logic.addTodo(todos, newTodo)
const expected = todos;
t.deepEqual(actual, expected, 'original todo\'s stay the same');
t.end();
});
test('new todos have an additional element', function(t) {
const actual = logic.addTodo(todos, newTodo).length;
const expected = todos.length + 1;
t.deepEqual(actual, expected, 'new todos have an additional element');
t.end();
});
test('new object has three elements within', function(t) {
const actual = Object.values(logic.addTodo(todos, newTodo)[logic.addTodo(todos, newTodo).length-1]).length;
const expected = todos.length+1;
t.deepEqual(actual, expected, 'new object has three elements within');
t.end();
});
test('new element description is equal to newTodo', function(t) {
const actual = logic.addTodo(todos, newTodo)[logic.addTodo(todos, newTodo).length-1].description;
const expected = newTodo;
t.deepEqual(actual, expected, 'new element description is equal to newTodo');
t.end();
});
test('new element is default set to false', function(t) {
const actual = logic.addTodo(todos, newTodo)[logic.addTodo(todos, newTodo).length-1].done;
const expected = false;
t.deepEqual(actual, expected, 'new element description is equal to newTodo');
t.end();
});
test('new element ID is a number', function(t) {
const actual = typeof logic.addTodo(todos, newTodo)[logic.addTodo(todos, newTodo).length-1].id;
const expected = 'number';
t.deepEqual(actual, expected, 'New element ID is a number');
t.end();
});
/* TESTS RELATING TO THE markTodo FUNCTION */
var idToMark = 1;
test('original todo\'s stay the same', function(t) {
const actual = todos;
logic.markTodo(todos, idToMark)
const expected = todos;
t.deepEqual(actual, expected, 'original todo\'s stay the same');
t.end();
});
test('check done attribute of modified element is a boolean', function(t) {
const actual = typeof logic.markTodo(todos, idToMark)[idToMark].done; // this doesn't refer to the right
const expected = "boolean";
t.deepEqual(actual, expected, 'check done attribute of modified element is a boolean');
t.end();
});
test('check the idToMark element done has changed', function(t) {
var result = logic.markTodo(todos, idToMark);
const actual = result[idToMark].done !== todos[idToMark].done;
const expected = true;
//newTodos.map(function(item) {
// if (item.id == idToMark) {console.log(item); continue};
// else return item =
//}
t.deepEqual(actual, expected, 'check the idToMark element done has changed');
t.end();
});