fix(curriculum): improve getResults test to prevent TypeError in lab-quiz-game (#63993)

Co-authored-by: beng guan koay <bengguan.koay@ideagenplc.com>
This commit is contained in:
bengguankoay
2025-11-21 03:26:07 +08:00
committed by GitHub
parent 719c93c7db
commit f90905fbfe

View File

@@ -111,8 +111,10 @@ assert.isFunction(getResults);
Your `getResults` function should take the question object as the first parameter and the computer's choice as the second parameter.
```js
assert.equal(getResults(questions[0], questions[0].answer), `The computer's choice is correct!`);
assert.notEqual(getResults(questions[0].answer, questions[0]), `The computer's choice is correct!`);
const testQuestion = questions[0];
const wrongChoice = questions[0].choices.find(choice => choice !== questions[0].answer);
assert.equal(getResults(testQuestion, testQuestion.answer), `The computer's choice is correct!`);
assert.equal(getResults(testQuestion, wrongChoice), `The computer's choice is wrong. The correct answer is: ${testQuestion.answer}`);
```
If the computer choice matches the answer, `getResults` should return `The computer's choice is correct!`
@@ -127,6 +129,13 @@ If the computer choice doesn't match the answer, `getResults` should return `The
assert.equal(getResults({category: 'misc', choices: ['a', 'b', 'c'], question: "question?", answer: "b"}, "a"), `The computer's choice is wrong. The correct answer is: b`)
```
Your `getResults` function should use exact equality comparison, not substring matching.
```js
assert.equal(getResults({category: 'food', choices: ['Ham', 'Hamburger', 'Hot Dog'], question: "What food?", answer: "Hamburger"}, "Ham"), `The computer's choice is wrong. The correct answer is: Hamburger`);
assert.equal(getResults({category: 'food', choices: ['Ham', 'Hamburger', 'Hot Dog'], question: "What food?", answer: "Ham"}, "Hamburger"), `The computer's choice is wrong. The correct answer is: Ham`);
```
# --seed--
## --seed-contents--