-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test.js
117 lines (94 loc) · 3.02 KB
/
main.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
const { expect, describe } = require("@jest/globals");
const getComments = require("./__mocks__/getComments.js");
const getCommentsNode = require("./__mocks__/getCommentsNodes.js");
const itemCounter = require("./__mocks__/getItemsContainerNodes.js");
const getMeals = require("./__mocks__/getMeals.js");
const testArr = [{}, {}, {}, {}];
const testCommentNodes1 = `
<div class="comments">
<p class="comment">Comment 1</p>
<p class="comment">Comment 2</p>
<p class="comment">Comment 3</p>
</div>
`;
const testCommentNodes2 = `
<div class="comments">
</div>
`;
describe("Check nodeList length", () => {
test("Should return the comments count", () => {
document.body.innerHTML = getCommentsNode(testCommentNodes1);
const result = document.querySelectorAll(".comment");
expect(result.length).toBe(3);
});
test("should return zero if no count was found", () => {
document.body.innerHTML = getCommentsNode(testCommentNodes2);
const result = document.querySelectorAll(".comment");
expect(result.length).toBe(0);
});
});
const testItemNodes1 = `
<div class="cards">
<p class="item">item 1</p>
<p class="item">item 2</p>
<p class="item">item 3</p>
</div>
`;
const testItemNodes2 = `
<div class="cards">
</div>
`;
describe("Check items nodeList length", () => {
test("Should return the item count", () => {
document.body.innerHTML = itemCounter(testItemNodes1);
const result = document.querySelectorAll(".item");
expect(result.length).toBe(3);
});
test("should return zero if no items found", () => {
document.body.innerHTML = getCommentsNode(testItemNodes2);
const result = document.querySelectorAll(".item");
expect(result.length).toBe(0);
});
});
describe("Testing comments count", () => {
test("should return first value of arr", async () => {
const result = await getComments(testArr);
expect(result[0]).toEqual({});
});
test("should return arr length", async () => {
const result = await getComments(testArr);
expect(result.length).toBe(4);
});
});
const testMeals = [
{
strMeal: "Ayam Percik",
strMealThumb:
"https://www.themealdb.com/images/media/meals/020z181619788503.jpg",
idMeal: 53050,
},
{
strMeal: "Brown Stew Chicken",
strMealThumb:
"https://www.themealdb.com/images/media/meals/sypxpx1515365095.jpg",
idMeal: 52940,
},
];
describe("Testing Items count", () => {
test("should return first value of testMeals", async () => {
const result = await getMeals(testMeals);
expect(result[0]).toEqual(testMeals[0]);
});
test("should return testMeals length", async () => {
const result = await getMeals(testMeals);
expect(result.length).toBe(2);
});
test("should return id of first meal in testMeals ", async () => {
const result = await getMeals(testMeals);
expect(result[0].idMeal).toBe(53050);
});
test("should return name of second meal in testMeals ", async () => {
const result = await getMeals(testMeals);
expect(result[1].strMeal).toBe("Brown Stew Chicken");
});
});