-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.test.js
50 lines (44 loc) · 1.04 KB
/
test.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
/**
* @jest-environment jsdom
*/
// TEST FOR ITEMS COUNTER
const itemsArray = [];
const mockedApiLength = 20;
let count = 0; // count displays items count
const updateCount = (array) => {
for (let i = 0; i < mockedApiLength; i += 1) {
array.push(i);
count = array.length;
}
return array;
};
// TEST FOR COMMENTS COUNTER
const comments = [];
let commentsCount = 0;
const comment = {
item_id: '',
username: '',
comment: '',
};
const inputField = document.createElement('input');
inputField.value = 'ernest';
const textArea = document.createElement('textarea');
textArea.value = 'My comment';
const addComment = () => {
if (inputField.value.length !== 0) {
comment.username = inputField.value;
comment.comment = textArea.value;
comments.push(comment);
commentsCount = comments.length;
}
};
describe('counters', () => {
test('update items count', () => {
updateCount(itemsArray);
expect(count).toBe(20);
});
test('update comments count', () => {
addComment();
expect(commentsCount).toBe(1);
});
});