@@ -194,6 +194,30 @@ describe("Quiz", () => {
194
194
// Check if the correctAnswers property has been increased by 1
195
195
expect ( quiz . correctAnswers ) . toEqual ( 3 ) ;
196
196
} ) ;
197
+
198
+ it ( "should check if the answer is correct by comparing it to the 'answer' property of the current question" , ( ) => {
199
+ const testQuestions = [
200
+ { text : "Question 1" , choices : [ "a" , "b" , "c" ] , answer : "b" } ,
201
+ { text : "Question 2" , choices : [ "d" , "e" , "f" ] , answer : "f" } ,
202
+ { text : "Question 3" , choices : [ "x" , "y" , "z" ] , answer : "y" } ,
203
+ ] ;
204
+
205
+ // Get a random index from the test questions array
206
+ const randomQuestionIndex = Math . floor ( Math . random ( ) * testQuestions . length ) ;
207
+
208
+ // Instantiate a new Quiz object with the test questions
209
+ const quiz = new Quiz ( testQuestions , 60 , 60 ) ;
210
+ const initialCorrectAnswers = quiz . correctAnswers ;
211
+
212
+ // Manualy set the `quiz.currentQuestionIndex` to the random index
213
+ quiz . currentQuestionIndex = randomQuestionIndex ;
214
+
215
+ // Call the checkAnswer() method with the correct answer for the current question
216
+ quiz . checkAnswer ( testQuestions [ randomQuestionIndex ] . answer ) ;
217
+
218
+ // Check if the correctAnswers property has been increased by 1
219
+ expect ( quiz . correctAnswers ) . toEqual ( initialCorrectAnswers + 1 ) ;
220
+ } ) ;
197
221
} ) ;
198
222
199
223
describe ( "hasEnded() method" , ( ) => {
0 commit comments