-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
26 lines (22 loc) · 844 Bytes
/
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
const addTask = (taskList, taskText) => {
if (taskText.trim() === "") return;
const taskItem = document.createElement("li");
taskItem.textContent = taskText;
taskList.appendChild(taskItem);
return taskItem;
};
test("addTask function adds a new task to the list", () => {
document.body.innerHTML = '<ul id="task-list"></ul>';
const taskList = document.getElementById("task-list");
const taskText = "New Task";
const taskItem = addTask(taskList, taskText);
expect(taskList.children.length).toBe(1);
expect(taskItem.textContent).toBe(taskText);
});
test("addTask function does not add empty task", () => {
document.body.innerHTML = '<ul id="task-list"></ul>';
const taskList = document.getElementById("task-list");
const taskText = "";
addTask(taskList, taskText);
expect(taskList.children.length).toBe(0);
});