Skip to content

fix: add fake-timer tests for useQuiz timer auto-submit - #1320

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
payfoxX:ai-fix-issue-947
Aug 31, 2026
Merged

fix: add fake-timer tests for useQuiz timer auto-submit#1320
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
payfoxX:ai-fix-issue-947

Conversation

@payfoxX

@payfoxX payfoxX commented Aug 31, 2026

Copy link
Copy Markdown

closes #947

I implemented fake-timer tests for the useQuiz hook to verify the timer auto-submit functionality on expiry.

What I fixed
I added comprehensive tests that ensure the timer correctly auto-submits when it expires, that the timer clears upon completion, and that it does not run in review mode. These tests use vitest's fake timers to simulate time progression and assert the expected behavior based on the hook's API.

Issue before the fix
Before the change, the useQuiz hook's timer functionality was not tested. Specifically, there was no verification that complete() is called and isCompleted becomes true when the timer expires, that the interval is cleared on completion, or that the timer remains inactive in review mode. This lack of tests could lead to undetected bugs in the quiz completion logic, potentially causing issues such as quizzes not submitting automatically or timers running inappropriately.

Files changed

  • src/hooks/tests/useQuiz.test.tsx: Added new test cases within a 'timer auto-submit on expiry' describe block, using vitest's fake timers to advance time and assert state changes. Aligned test methods with the existing hook API by using result.current.actions.startQuiz, answerQuestion, and complete, and corrected imports to use Quiz and QuestionType from '@/types/quiz' for consistency with the codebase. Included tests for auto-submit at expiry, timer clearing on completion, and review mode behavior.

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@payfoxX Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project

@RUKAYAT-CODER
RUKAYAT-CODER merged commit ce7f1f5 into rinafcode:main Aug 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a fake-timer test for useQuiz timer auto-submit on expiry

2 participants