Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79aaa8f

Browse files
committed
refactor(test): move day 2 tests to an existing file
1 parent ae40d48 commit 79aaa8f

File tree

3 files changed

+71
-44
lines changed

3 files changed

+71
-44
lines changed

SpecRunner.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
<!-- include source files here... -->
1515
<script src="src/quiz.js"></script>
1616
<script src="src/question.js"></script>
17-
<script src="src/index.js"></script>
1817

1918
<!-- include spec files here... -->
2019
<script src="tests/question.spec.js"></script>
2120
<script src="tests/quiz.spec.js"></script>
22-
<script src="tests/index.spec.js"></script>
2321
</head>
2422

2523
<body></body>

tests/index.spec.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/quiz.spec.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,41 @@ describe("Quiz", () => {
229229
});
230230
});
231231

232-
describe("filterQuestionsByDifficulty() method", () => {
232+
// ****************************************************************************************************
233+
// DAY 2
234+
//
235+
// The 1st test is already written for you - checking if the 'filter()' array method is used.
236+
//
237+
// The test block below is currently skipped ('xdescribe').
238+
// Once you start working on the tests, change the 'xdescribe' to 'describe' to enable the tests.
239+
// ****************************************************************************************************
240+
241+
xdescribe("filterQuestionsByDifficulty() method", () => {
242+
it("should use the 'filter()' array method on the 'questions' array", () => {
243+
// Instantiate a new Quiz object
244+
const quiz = new Quiz([], "test", 60);
245+
// Set up a spy on the 'filter()' array method to track calls to it
246+
const filterSpy = spyOn(quiz.questions, "filter");
247+
248+
// Call the 'filterQuestionsByDifficulty()' method
249+
quiz.filterQuestionsByDifficulty(1);
250+
251+
// Check if the 'filter()' array method was called on the 'questions' array
252+
expect(filterSpy).toHaveBeenCalled();
253+
// Check that the 'filter()' array method was called only once
254+
expect(filterSpy).toHaveBeenCalledTimes(1);
255+
// Check that the 'filter()' array method was called correctly, with a function as its argument
256+
expect(filterSpy).toHaveBeenCalledWith(jasmine.any(Function));
257+
});
258+
259+
260+
// ****************************************************************************************************
261+
// DAY 2: 'filterQuestionsByDifficulty()' method
262+
//
263+
// Below are 4 tests that you need to write for the 'filterQuestionsByDifficulty()' method.
264+
// ****************************************************************************************************
265+
266+
233267
it("should be defined", () => {
234268
// YOUR CODE HERE:
235269
//
@@ -245,7 +279,6 @@ describe("Quiz", () => {
245279
// 1. Instantiate a new Quiz object
246280

247281
// 2. Check if the .filterQuestionsByDifficulty is a function
248-
249282
});
250283

251284
it("should receive 1 argument (difficulty)", () => {
@@ -334,7 +367,42 @@ describe("Quiz", () => {
334367
});
335368
});
336369

337-
describe("averageDifficulty() method", () => {
370+
371+
// ****************************************************************************************************
372+
// DAY 2
373+
//
374+
// The 1st test is already written for you - checking if the 'reduce()' array method is used.
375+
//
376+
// The test block below is currently skipped ('xdescribe').
377+
// Once you start working on the tests, change the 'xdescribe' to 'describe' to enable the tests.
378+
// ****************************************************************************************************
379+
380+
xdescribe("averageDifficulty() method", () => {
381+
it("should use the 'reduce()' array method on the 'questions' array", () => {
382+
// Instantiate a new Quiz object
383+
const quiz = new Quiz([], "test", 60);
384+
// Set up a spy on the 'reduce()' array method to track calls to it
385+
const reduceSpy = spyOn(quiz.questions, "reduce");
386+
387+
// Call the 'averageDifficulty()' method
388+
quiz.averageDifficulty();
389+
390+
// Check if the 'reduce()' array method was called on the 'questions' array
391+
expect(reduceSpy).toHaveBeenCalled();
392+
// Check that the 'reduce()' array method was called only once
393+
expect(reduceSpy).toHaveBeenCalledTimes(1);
394+
// Check that the 'reduce()' array method was called correctly, with a function as its 1st argument and optional 2nd argument
395+
expect(reduceSpy.calls.allArgs()[0][0]).toEqual(jasmine.any(Function));
396+
});
397+
398+
399+
// ****************************************************************************************************
400+
// DAY 2: 'averageDifficulty()' method
401+
//
402+
// Below are 4 tests that you need to write for the 'averageDifficulty()' method.
403+
// ****************************************************************************************************
404+
405+
338406
it("should be defined", () => {
339407
// YOUR CODE HERE:
340408
//

0 commit comments

Comments
 (0)