|
1 | 1 | describe("JavaScript Basics Continued", function () {
|
2 |
| - beforeEach(function () { |
3 |
| - spyOn(console, "log"); |
4 |
| - }); |
5 |
| - |
6 |
| - afterEach(function () { |
7 |
| - console.log.calls.reset(); |
8 |
| - }); |
9 |
| - |
10 |
| - describe("Task 6: Control Structures - Conditional Statements", function () { |
11 |
| - it("should define a variable named studentGrade that is of type number", function () { |
12 |
| - expect(studentGrade).toBeDefined(); |
13 |
| - expect(typeof studentGrade).toBe("number"); |
14 |
| - }); |
15 |
| - it("should declare a function named gradeCommentary that takes no arguments", function () { |
16 |
| - expect(gradeCommentary).toBeDefined(); |
17 |
| - expect(gradeCommentary.length).toBe(0); |
18 |
| - }); |
19 |
| - it("should log 'Excellent work!' for a grade of 90 or above", function () { |
20 |
| - studentGrade = 90; |
21 |
| - gradeCommentary(); |
22 |
| - expect(console.log).toHaveBeenCalledWith("Excellent work!"); |
| 2 | + beforeEach(function () { |
| 3 | + spyOn(console, "log"); |
23 | 4 | });
|
24 | 5 |
|
25 |
| - it("should log 'Good job!' for grades between 80 and 89", function () { |
26 |
| - studentGrade = 85; |
27 |
| - gradeCommentary(); |
28 |
| - expect(console.log).toHaveBeenCalledWith("Good job!"); |
| 6 | + afterEach(function () { |
| 7 | + console.log.calls.reset(); |
29 | 8 | });
|
30 | 9 |
|
31 |
| - it("should log 'You passed.' for grades between 70 and 79", function () { |
32 |
| - studentGrade = 75; |
33 |
| - gradeCommentary(); |
34 |
| - expect(console.log).toHaveBeenCalledWith("You passed."); |
35 |
| - }); |
| 10 | + describe("Task 6: Control Structures - Conditional Statements", function () { |
| 11 | + it("should define a variable named studentGrade that is of type number", function () { |
| 12 | + expect(studentGrade).toBeDefined(); |
| 13 | + expect(typeof studentGrade).toBe("number"); |
| 14 | + }); |
| 15 | + it("should declare a function named gradeCommentary that takes no arguments", function () { |
| 16 | + expect(gradeCommentary).toBeDefined(); |
| 17 | + expect(gradeCommentary.length).toBe(0); |
| 18 | + }); |
| 19 | + it("should log 'Excellent work!' for a grade of 90 or above", function () { |
| 20 | + studentGrade = 90; |
| 21 | + gradeCommentary(); |
| 22 | + expect(console.log).toHaveBeenCalledWith("Excellent work!"); |
| 23 | + }); |
36 | 24 |
|
37 |
| - it("should log 'Needs improvement.' for grades below 70", function () { |
38 |
| - studentGrade = 65; |
39 |
| - gradeCommentary(); |
40 |
| - expect(console.log).toHaveBeenCalledWith("Needs improvement."); |
41 |
| - }); |
42 |
| - }); |
| 25 | + it("should log 'Good job!' for grades between 80 and 89", function () { |
| 26 | + studentGrade = 85; |
| 27 | + gradeCommentary(); |
| 28 | + expect(console.log).toHaveBeenCalledWith("Good job!"); |
| 29 | + }); |
43 | 30 |
|
44 |
| - describe("Task 7: Control Structures - Loops", function () { |
45 |
| - it("should declare a function named logNumbers that takes no arguments", function () { |
46 |
| - expect(logNumbers).toBeDefined(); |
47 |
| - expect(logNumbers.length).toBe(0); |
48 |
| - }); |
49 |
| - it("should log numbers from 1 to 10", function () { |
50 |
| - logNumbers(); |
51 |
| - for (let i = 1; i <= 10; i++) { |
52 |
| - expect(console.log).toHaveBeenCalledWith(i); |
53 |
| - } |
54 |
| - }); |
55 |
| - it("should declare a function named countByTwos that takes no arguments", function () { |
56 |
| - expect(countByTwos).toBeDefined(); |
57 |
| - expect(countByTwos.length).toBe(0); |
58 |
| - }); |
59 |
| - it("should log even numbers from 2 to 20", function () { |
60 |
| - countByTwos(); |
61 |
| - for (let i = 2; i <= 20; i += 2) { |
62 |
| - expect(console.log).toHaveBeenCalledWith(i); |
63 |
| - } |
64 |
| - }); |
65 |
| - it("should declare a function named triangle that takes no arguements", function () { |
66 |
| - expect(triangle).toBeDefined(); |
67 |
| - expect(triangle.length).toBe(0); |
68 |
| - }); |
69 |
| - it("should log a seven line triangle of # characters", function () { |
70 |
| - triangle(); |
71 |
| - for (let i = 1; i <= 7; i++) { |
72 |
| - expect(console.log).toHaveBeenCalledWith("#".repeat(i)); |
73 |
| - } |
74 |
| - }); |
75 |
| - }); |
| 31 | + it("should log 'You passed.' for grades between 70 and 79", function () { |
| 32 | + studentGrade = 75; |
| 33 | + gradeCommentary(); |
| 34 | + expect(console.log).toHaveBeenCalledWith("You passed."); |
| 35 | + }); |
76 | 36 |
|
77 |
| - describe("Task 8: More on Functions", function () { |
78 |
| - it("should declare a function named calculateArea that takes two arguments: length and width", function () { |
79 |
| - expect(calculateArea).toBeDefined(); |
80 |
| - expect(calculateArea.length).toBe(2); |
81 |
| - }); |
82 |
| - it("should calculate area correctly", function () { |
83 |
| - expect(calculateArea(5, 10)).toEqual(50); |
84 |
| - expect(calculateArea(0, 10)).toEqual(0); |
85 |
| - expect(calculateArea(-5, 10)).toBeNaN(); // Edge case: Negative dimensions are not physically meaningful, so expect a NaN |
86 |
| - }); |
87 |
| - it("should declare a function expression named greetPerson that takes a name as an argument", function () { |
88 |
| - expect(greetPerson).toBeDefined(); |
89 |
| - expect(greetPerson.length).toBe(1); |
| 37 | + it("should log 'Needs improvement.' for grades below 70", function () { |
| 38 | + studentGrade = 65; |
| 39 | + gradeCommentary(); |
| 40 | + expect(console.log).toHaveBeenCalledWith("Needs improvement."); |
| 41 | + }); |
90 | 42 | });
|
91 |
| - it("should greet a person correctly", function () { |
92 |
| - greetPerson("Alice"); |
93 |
| - expect(console.log).toHaveBeenCalledWith("Hello, Alice!"); |
94 |
| - }); |
95 |
| - }); |
96 | 43 |
|
97 |
| - describe("Task 9: Objects and Properties", function () { |
98 |
| - it("should declare an object named book with properties: title, author, and year", function () { |
99 |
| - expect(book).toBeDefined(); |
100 |
| - expect(book.title).toBeDefined(); |
101 |
| - expect(book.author).toBeDefined(); |
102 |
| - expect(book.year).toBeDefined(); |
103 |
| - }); |
104 |
| - it("should declare a function named logBookTitle that takes no arguments", function () { |
105 |
| - expect(logBookTitle).toBeDefined(); |
106 |
| - expect(logBookTitle.length).toBe(0); |
| 44 | + describe("Task 7: Control Structures - Loops", function () { |
| 45 | + it("should declare a function named logNumbers that takes no arguments", function () { |
| 46 | + expect(logNumbers).toBeDefined(); |
| 47 | + expect(logNumbers.length).toBe(0); |
| 48 | + }); |
| 49 | + it("should log numbers from 1 to 10", function () { |
| 50 | + logNumbers(); |
| 51 | + for (let i = 1; i <= 10; i++) { |
| 52 | + expect(console.log).toHaveBeenCalledWith(i); |
| 53 | + } |
| 54 | + }); |
| 55 | + it("should declare a function named countByTwos that takes no arguments", function () { |
| 56 | + expect(countByTwos).toBeDefined(); |
| 57 | + expect(countByTwos.length).toBe(0); |
| 58 | + }); |
| 59 | + it("should log even numbers from 2 to 20", function () { |
| 60 | + countByTwos(); |
| 61 | + for (let i = 2; i <= 20; i += 2) { |
| 62 | + expect(console.log).toHaveBeenCalledWith(i); |
| 63 | + } |
| 64 | + }); |
| 65 | + it("should declare a function named triangle that takes no arguements", function () { |
| 66 | + expect(triangle).toBeDefined(); |
| 67 | + expect(triangle.length).toBe(0); |
| 68 | + }); |
| 69 | + it("should log a seven line triangle of # characters", function () { |
| 70 | + triangle(); |
| 71 | + for (let i = 1; i <= 7; i++) { |
| 72 | + expect(console.log).toHaveBeenCalledWith("#".repeat(i)); |
| 73 | + } |
| 74 | + }); |
107 | 75 | });
|
108 |
| - it("should log the book's title correctly", function () { |
109 |
| - logBookTitle(); |
110 |
| - expect(console.log).toHaveBeenCalledWith(book.title); |
111 |
| - }); |
112 |
| - it("should declare a function named updateYear that takes no arguments", function () { |
113 |
| - expect(updateYear).toBeDefined(); |
114 |
| - expect(updateYear.length).toBe(0); |
115 |
| - }); |
116 |
| - it("should update the book's year correctly", function () { |
117 |
| - let currentYear = new Date().getFullYear(); |
118 |
| - updateYear(); |
119 |
| - expect(book.year).toEqual(currentYear); |
120 |
| - }); |
121 |
| - it("should declare a function named addGenre that takes no arguments", function () { |
122 |
| - expect(addGenre).toBeDefined(); |
123 |
| - expect(addGenre.length).toBe(0); |
| 76 | + |
| 77 | + describe("Task 8: More on Functions", function () { |
| 78 | + it("should declare a function named calculateArea that takes two arguments: length and width", function () { |
| 79 | + expect(calculateArea).toBeDefined(); |
| 80 | + expect(calculateArea.length).toBe(2); |
| 81 | + }); |
| 82 | + it("should calculate area correctly", function () { |
| 83 | + expect(calculateArea(5, 10)).toEqual(50); |
| 84 | + expect(calculateArea(0, 10)).toEqual(0); |
| 85 | + expect(calculateArea(-5, 10)).toBeNaN(); // Edge case: Negative dimensions are not physically meaningful, so expect a NaN |
| 86 | + }); |
| 87 | + it("should declare a function expression named greetPerson that takes a name as an argument", function () { |
| 88 | + expect(greetPerson).toBeDefined(); |
| 89 | + expect(greetPerson.length).toBe(1); |
| 90 | + }); |
| 91 | + it("should greet a person correctly", function () { |
| 92 | + greetPerson("Alice"); |
| 93 | + expect(console.log).toHaveBeenCalledWith("Hello, Alice!"); |
| 94 | + }); |
124 | 95 | });
|
125 |
| - it("should add a genre property to the book", function () { |
126 |
| - addGenre(); |
127 |
| - expect(book.genre).toBeDefined(); |
| 96 | + |
| 97 | + describe("Task 9: Objects and Properties", function () { |
| 98 | + it("should declare an object named book with properties: title, author, and year", function () { |
| 99 | + expect(book).toBeDefined(); |
| 100 | + expect(book.title).toBeDefined(); |
| 101 | + expect(book.author).toBeDefined(); |
| 102 | + expect(book.year).toBeDefined(); |
| 103 | + }); |
| 104 | + it("should declare a function named logBookTitle that takes no arguments", function () { |
| 105 | + expect(logBookTitle).toBeDefined(); |
| 106 | + expect(logBookTitle.length).toBe(0); |
| 107 | + }); |
| 108 | + it("should log the book's title correctly", function () { |
| 109 | + logBookTitle(); |
| 110 | + expect(console.log).toHaveBeenCalledWith(book.title); |
| 111 | + }); |
| 112 | + it("should declare a function named updateYear that takes no arguments", function () { |
| 113 | + expect(updateYear).toBeDefined(); |
| 114 | + expect(updateYear.length).toBe(0); |
| 115 | + }); |
| 116 | + it("should update the book's year correctly", function () { |
| 117 | + let currentYear = new Date().getFullYear(); |
| 118 | + updateYear(); |
| 119 | + expect(book.year).toEqual(currentYear); |
| 120 | + }); |
| 121 | + it("should declare a function named addGenre that takes no arguments", function () { |
| 122 | + expect(addGenre).toBeDefined(); |
| 123 | + expect(addGenre.length).toBe(0); |
| 124 | + }); |
| 125 | + it("should add a genre property to the book", function () { |
| 126 | + addGenre(); |
| 127 | + expect(book.genre).toBeDefined(); |
| 128 | + }); |
128 | 129 | });
|
129 |
| - }); |
130 | 130 | });
|
0 commit comments