Skip to content

test: add comprehensive tests for YAxis interval={0} behavior#6714

Merged
ckifer merged 1 commit intorecharts:mainfrom
Advikkhandelwal:fix/yaxis-interval-zero-tests
Dec 3, 2025
Merged

test: add comprehensive tests for YAxis interval={0} behavior#6714
ckifer merged 1 commit intorecharts:mainfrom
Advikkhandelwal:fix/yaxis-interval-zero-tests

Conversation

@Advikkhandelwal
Copy link
Contributor

@Advikkhandelwal Advikkhandelwal commented Dec 1, 2025

Description

This PR adds comprehensive test cases to verify that interval={0} on YAxis correctly displays all custom ticks, addressing issue #6699.

Changes

  • Added new test file test/cartesian/YAxis/YAxis.interval-zero.spec.tsx with 4 test cases:
    1. Verify all 9 ticks are displayed with interval={0} in standard chart size
    2. Verify all 9 ticks are displayed with interval={0} in small chart height
    3. Verify all 9 ticks are displayed with interval={0} and large minTickGap
    4. Verify interval={1} correctly skips every other tick

Testing

All tests pass successfully:

  • ✅ 4 new tests added
  • ✅ All 113 YAxis tests pass
  • ✅ Full test suite passes (5787 tests passed, 18 skipped)

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.ts correctly handles numeric interval values by returning early from getNumberIntervalTicks(), which bypasses the visibility filtering logic. When interval=0, it returns all ticks without any filtering.

These test cases serve to:

  1. Document the expected behavior of interval={0}
  2. Prevent regression in future changes
  3. Provide clarity to users about how interval values work

Closes #6699

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for YAxis interval behavior, validating tick rendering and labeling across various configurations including custom tick displays and interval settings.

✏️ Tip: You can customize this high-level summary in your review settings.

- 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

Adds a test suite for YAxis with interval={0} to validate custom tick rendering and labeling. Tests verify that all custom ticks display under various conditions including different component sizes, tick gap constraints, and interval settings.

Changes

Cohort / File(s) Summary
YAxis interval test suite
test/cartesian/YAxis/YAxis.interval-zero.spec.tsx
Comprehensive test cases validating tick rendering with interval={0} and custom ticks array; tests cover standard and reduced sizes, large minTickGap handling, and interval={1} behavior

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single test file addition with straightforward assertions
  • No structural changes to implementation code
  • Tests are repetitive in pattern (render → assert DOM structure)

Possibly related PRs

Suggested reviewers

  • ckifer
  • PavelVanecek

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding comprehensive tests for YAxis interval={0} behavior.
Description check ✅ Passed The PR description covers key sections including detailed changes, test results, investigation findings, and issue closure, though it deviates from the template structure.
Linked Issues check ✅ Passed The PR adds test cases to verify interval={0} displays all ticks [#6699], with tests confirming the expected behavior works correctly in the current codebase.
Out of Scope Changes check ✅ Passed All changes are limited to adding test cases for YAxis interval={0} behavior directly related to issue #6699; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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/assertions

The 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 tests

Per the test guidelines, component specs are expected to:

  • Use vi.useFakeTimers() (due to timer / requestAnimationFrame usage), and
  • Mock getBoundingClientRect via test/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 setupTests that 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

📥 Commits

Reviewing files that changed from the base of the PR and between 837d76f and 0036454.

📒 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 use any type (implicit or explicit) in TypeScript code
Prefer unknown over any and 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 use as type assertions in TypeScript; the only exception is as 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 test or www/test directories with .spec.tsx file 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 lint and 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 the createSelectorTestCase helper function when writing or modifying tests
Use the expectLastCalledWith helper function instead of expect(spy).toHaveBeenLastCalledWith(...) for better typing and autocompletion
Verify the number of selector calls using the spy object from createSelectorTestCase to spot unnecessary re-renders and improve performance
Mock getBoundingClientRect in tests using the helper function provided in test/helper/MockGetBoundingClientRect.ts
Use vi.useFakeTimers() in all tests due to Redux autoBatchEnhancer dependency on timers and requestAnimationFrame
Call vi.runOnlyPendingTimers() to advance timers after renders when not using createSelectorTestCase helper, and avoid vi.runAllTimers() to prevent infinite loops
Use userEvent.setup({ advanceTimers: vi.runOnlyPendingTimers }) or the userEventSetup helper function from test/helper/userEventSetup.ts when creating userEvent instances
When testing tooltips on hover, use vi.runOnlyPendingTimers() after each userEvent.hover() call or use the showTooltip helper function from tooltipTestHelpers.ts to 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.tsx rather than running all tests with npm 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} scenario

The shared data / customTicks setup and the first test’s strict equality check on all 9 labels align well with the #6699 reproduction and clearly document the expected behavior for interval={0}. No changes needed here.

@codecov
Copy link

codecov bot commented Dec 1, 2025

Bundle Report

Bundle size has no change ✅

@ckifer ckifer merged commit 448ea0c into recharts:main Dec 3, 2025
58 of 59 checks passed
@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.03%. Comparing base (837d76f) to head (0036454).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai bot mentioned this pull request Jan 20, 2026
8 tasks
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.

YAxis interval={0} does not force display of all ticks when using custom ticks array

3 participants