-
Notifications
You must be signed in to change notification settings - Fork 10
/
challenge.test.js
57 lines (53 loc) · 1.98 KB
/
challenge.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
const { getStudentsByCourse, listAllCourses } = require("./objectIteration");
xdescribe("🌶️🌶️🌶️ Challenges", () => {
let students;
beforeEach(() => {
students = [
{ id: 1, name: "Alice", courses: ["Math", "Science", "History"] },
{ id: 2, name: "Bob", courses: ["History", "English", "Math", "Art"] },
{ id: 3, name: "Charlie", courses: ["Science", "English", "Music"] },
{ id: 4, name: "David", courses: ["Math", "History", "Art", "PE"] },
{ id: 5, name: "Eva", courses: ["Science", "Math", "Music"] },
{ id: 6, name: "Frank", courses: ["English", "Art"] },
{
id: 7,
name: "Grace",
courses: ["Math", "Science", "English", "Music"],
},
{ id: 8, name: "Helen", courses: ["History", "Art", "PE"] },
{ id: 9, name: "Ivy", courses: ["Science", "English", "Art"] },
{ id: 10, name: "Jack", courses: ["Math", "History", "Music"] },
];
});
describe("getStudentsByCourse 🌶️🌶️", () => {
it("should return an array of student objects enrolled in a specified course", () => {
const enrolledStudents = getStudentsByCourse(students, "Music");
expect(enrolledStudents).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: 3, name: "Charlie" }),
expect.objectContaining({ id: 5, name: "Eva" }),
expect.objectContaining({ id: 7, name: "Grace" }),
expect.objectContaining({ id: 10, name: "Jack" }),
])
);
expect(enrolledStudents.length).toBe(4);
});
});
describe("listAllCourses 🌶️🌶️🌶️", () => {
it("should return an array of all unique course names", () => {
const allCourses = listAllCourses(students);
expect(allCourses).toEqual(
expect.arrayContaining([
"Math",
"Science",
"History",
"English",
"Art",
"Music",
"PE",
])
);
expect(allCourses.length).toBe(7);
});
});
});