test: add comprehensive tests for YAxis interval={0} behavior#6714
Conversation
- Add tests to verify interval={0} displays all custom ticks
- Test with various chart sizes and minTickGap values
- Verify interval={1} correctly skips every other tick
- Closes recharts#6699
WalkthroughAdds a test suite for YAxis with Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx (2)
26-63: Consider extracting a small helper for tick selection/assertionsThe sequence
const allTicks = container.querySelectorAll('.recharts-yAxis-tick-labels .recharts-cartesian-axis-tick-value'); const tickTexts = Array.from(allTicks).map(tick => tick.textContent);is repeated across multiple tests. You could DRY this up with a
getYAxisTickTexts(container)helper and optionally assert the full ordered list in the “small height” and “large minTickGap” tests for consistency with the first test. This is purely for readability and consistency; current assertions are fine.Based on learnings, using small helpers tends to keep spec files easier to extend over time.
1-81: Verify timer and layout mocking expectations for component testsPer the test guidelines, component specs are expected to:
- Use
vi.useFakeTimers()(due to timer /requestAnimationFrameusage), and- Mock
getBoundingClientRectviatest/helper/MockGetBoundingClientRect.ts.This file doesn’t do either explicitly. If these concerns are already handled in a shared test setup (e.g., a global
setupTeststhat configures fake timers and layout mocks), then you’re good. Otherwise, consider wiring them in here or at the suite level to avoid future flakiness as Recharts’ internals evolve.Based on learnings, centralized timer and layout mocking help keep React Testing Library–based component tests stable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
Run type checking on the codebase using
npm run check-types
**/*.{ts,tsx}: Never useanytype (implicit or explicit) in TypeScript code
Preferunknownoveranyand refine the type in TypeScript
Type function parameters and return values explicitly in TypeScript, do not rely on implicit any or inference; exceptions are React components and trivial functions
Do not useastype assertions in TypeScript; the only exception isas const
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
{test,www/test}/**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
Write unit tests in the
testorwww/testdirectories with.spec.tsxfile extension
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
test/**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Aim for 100% unit test code coverage when writing new code
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Ensure code lints by running
npm run lintand follows Airbnb's Style Guide
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
test/**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (test/README.md)
test/**/*.{test,spec}.{ts,tsx}: Aim for 100% unit test code coverage when writing new code
Prefer to use thecreateSelectorTestCasehelper function when writing or modifying tests
Use theexpectLastCalledWithhelper function instead ofexpect(spy).toHaveBeenLastCalledWith(...)for better typing and autocompletion
Verify the number of selector calls using the spy object fromcreateSelectorTestCaseto spot unnecessary re-renders and improve performance
MockgetBoundingClientRectin tests using the helper function provided intest/helper/MockGetBoundingClientRect.ts
Usevi.useFakeTimers()in all tests due to Redux autoBatchEnhancer dependency on timers andrequestAnimationFrame
Callvi.runOnlyPendingTimers()to advance timers after renders when not usingcreateSelectorTestCasehelper, and avoidvi.runAllTimers()to prevent infinite loops
UseuserEvent.setup({ advanceTimers: vi.runOnlyPendingTimers })or theuserEventSetuphelper function fromtest/helper/userEventSetup.tswhen creating userEvent instances
When testing tooltips on hover, usevi.runOnlyPendingTimers()after eachuserEvent.hover()call or use theshowTooltiphelper function fromtooltipTestHelpers.tsto account for requestAnimationFrame delays
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
When running unit tests, prefer to run a single test file using
npm run test -- path/to/TestFile.spec.tsxrather than running all tests withnpm test
Files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
🧠 Learnings (2)
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Verify the number of selector calls using the spy object from `createSelectorTestCase` to spot unnecessary re-renders and improve performance
Applied to files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
📚 Learning: 2025-11-25T01:22:59.729Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.729Z
Learning: Applies to test/component/**/*.spec.tsx : Use React Testing Library for testing component interactions and behavior upon rendering
Applied to files:
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
🔇 Additional comments (1)
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx (1)
7-31: Good coverage of the core interval={0} scenarioThe shared
data/customTickssetup and the first test’s strict equality check on all 9 labels align well with the #6699 reproduction and clearly document the expected behavior forinterval={0}. No changes needed here.
Bundle ReportBundle size has no change ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6714 +/- ##
=======================================
Coverage 94.03% 94.03%
=======================================
Files 500 500
Lines 42662 42662
Branches 4901 4901
=======================================
Hits 40116 40116
Misses 2541 2541
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This PR adds comprehensive test cases to verify that
interval={0}on YAxis correctly displays all custom ticks, addressing issue #6699.Changes
test/cartesian/YAxis/YAxis.interval-zero.spec.tsxwith 4 test cases:interval={0}in standard chart sizeinterval={0}in small chart heightinterval={0}and largeminTickGapinterval={1}correctly skips every other tickTesting
All tests pass successfully:
Findings
After thorough investigation, the reported issue in #6699 cannot be reproduced in the current codebase (v3.5.1) or even in v3.2.0. The
interval={0}functionality works correctly and displays all custom ticks as expected, including the "0" tick mentioned in the issue.The implementation in
src/cartesian/getTicks.tscorrectly handles numeric interval values by returning early fromgetNumberIntervalTicks(), which bypasses the visibility filtering logic. Wheninterval=0, it returns all ticks without any filtering.These test cases serve to:
interval={0}Closes #6699
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.