GitHub Issue: Failing Jest Tests for Answer Comparison and Time Conversion Functions
Issue Description
We are encountering several test failures related to the compareAnswer, convertToMinutesAndSeconds, and convertToTotalSeconds functions. Additionally, there are warnings regarding deprecated ts-jest configurations. The following errors and warnings were observed during testing:
bash
ts-jest[ts-jest-transformer] (WARN) Define ts-jest config under globals is deprecated. Please do
transform: {
: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
FAIL src/functions/nextQuestion/nextQuestion.test.ts
● Test suite failed to run
src/functions/nextQuestion/nextQuestion.test.ts:7:50 - error TS2322: Type 'string' is not assignable to type 'string[]'.
7 { id: 1, tag: 'tag1', question: 'question1', correct_answer: 'correct1', options: []},
~~~~~~~~~~~~~~
prisma/dataTypes.ts:14:3
14 correct_answer: string[];
~~~~~~~~~~~~~~
The expected type comes from property 'correct_answer' which is declared here on type 'QuestionType'
src/functions/nextQuestion/nextQuestion.test.ts:8:50 - error TS2322: Type 'string' is not assignable to type 'string[]'.
8 { id: 2, tag: 'tag2', question: 'question2', correct_answer: 'correct2', options: []},
~~~~~~~~~~~~~~
prisma/dataTypes.ts:14:3
14 correct_answer: string[];
~~~~~~~~~~~~~~
The expected type comes from property 'correct_answer' which is declared here on type 'QuestionType'
src/functions/nextQuestion/nextQuestion.test.ts:9:50 - error TS2322: Type 'string' is not assignable to type 'string[]'.
9 { id: 3, tag: 'tag3', question: 'question3', correct_answer: 'correct3', options: []},
~~~~~~~~~~~~~~
prisma/dataTypes.ts:14:3
14 correct_answer: string[];
~~~~~~~~~~~~~~
The expected type comes from property 'correct_answer' which is declared here on type 'QuestionType'
src/functions/nextQuestion/nextQuestion.test.ts:10:50 - error TS2322: Type 'string' is not assignable to type 'string[]'.
10 { id: 4, tag: 'tag4', question: 'question4', correct_answer: 'correct4', options: []},
~~~~~~~~~~~~~~
prisma/dataTypes.ts:14:3
14 correct_answer: string[];
~~~~~~~~~~~~~~
The expected type comes from property 'correct_answer' which is declared here on type 'QuestionType'
(node:6447) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:6449) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:6448) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
PASS src/functions/generateSessionID/generateCookieID.test.ts
PASS src/functions/convertToTotalSeconds/convertToTotalSeconds.test.ts
(node:6446) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
FAIL src/functions/setCorrectorIncorrectQs/setCorrectorIncorrectQs.test.ts
● setCorrectorIncorrectQs function › should check if answer is already in Correct Array, if so removes answer and place into inCorrect Array
expect(received).not.toContain(expected) // indexOf
Expected value: not 1432
Received array: [1432, 1142, 1242]
25 |
26 | // This expect is failing
> 27 | expect(QuizContext.Correct_Answered).not.toContain(questionID);
| ^
28 | // expect(QuizContext.SET_INCORRECT_ANSWERED).toHaveBeenCalledWith(questionID);
29 |
30 | });
at Object. (src/functions/setCorrectorIncorrectQs/setCorrectorIncorrectQs.test.ts:27:45)
● setCorrectorIncorrectQs function › should check if answer is already in incorrect Array, if so removes answer and place into Correct Array
expect(received).not.toContain(expected) // indexOf
Expected value: not 155
Received array: [155, 156, 457]
37 | setCorrectorIncorrectQs(QuizContext, questionID, isCorrect);
38 |
> 39 | expect(QuizContext.Incorrect_Answered).not.toContain(questionID);
| ^
40 | expect(QuizContext.Correct_Answered).toContain(questionID);
41 | // expect(QuizContext.SET_INCORRECT_ANSWERED).toHaveBeenCalledWith(questionID);
42 |
at Object. (src/functions/setCorrectorIncorrectQs/setCorrectorIncorrectQs.test.ts:39:47)
Test Suites: 2 failed, 2 passed, 4 total
Tests: 2 failed, 5 passed, 7 total
Snapshots: 0 total
Time: 5.298 s
Steps to Reproduce
Clone the repository and navigate to the project directory.
Run the test command: npm test.
Observe the test failures and warnings.
Expected Behavior
All tests should pass, and there should be no warnings related to deprecated configurations.
Actual Behavior
Tests for compareAnswer, convertToMinutesAndSeconds, and convertToTotalSeconds functions are failing.
Warnings about deprecated ts-jest configurations are shown.
GitHub Issue: Failing Jest Tests for Answer Comparison and Time Conversion Functions Issue Description
We are encountering several test failures related to the compareAnswer, convertToMinutesAndSeconds, and convertToTotalSeconds functions. Additionally, there are warnings regarding deprecated ts-jest configurations. The following errors and warnings were observed during testing:
bash
ts-jest[ts-jest-transformer] (WARN) Define
ts-jest
config underglobals
is deprecated. Please do transform: {