Skip to content

test: add unit tests for usePrevious hook #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

broBinChen
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

N/A - This is a proactive improvement to increase test coverage for the usePrevious hook.

💡 Background and solution

Problem:
The usePrevious hook was missing unit tests, which could lead to potential regressions and makes it harder to maintain code quality and reliability.

Solution:
Added comprehensive unit tests for the usePrevious hook with 15 test cases covering:

  1. Basic functionality: Hook definition, initial values, readonly behavior
  2. State tracking: Previous value tracking for primitives, strings, objects, and computed refs
  3. Custom shouldUpdate function: Custom update logic, undefined handling, conditional updates
  4. Default shouldUpdate behavior: Object.is comparison, NaN handling
  5. Edge cases: Rapid state changes, boolean values, null/undefined values

All tests pass successfully, ensuring the hook works correctly across various scenarios and edge cases.

📝 Changelog

Language Changelog
🇺🇸 English Internal improvement: Added comprehensive unit tests for usePrevious hook (no user-facing changes)
🇨🇳 Chinese 内部改进:为 usePrevious hook 添加了全面的单元测试(无用户侧变化)

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Follow our Code of Conduct
  • Read the Contributing Guidelines
  • Read the docs
  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. We will check and reply to you as soon as possible.

@NelsonYong NelsonYong merged commit 467b3b2 into InhiblabCore:master Jul 16, 2025
8 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.

2 participants