Add tests trying to reproduce 7362#7379
Conversation
WalkthroughThis PR adds comprehensive test coverage for Recharts YAxis issue ChangesYAxis Issue
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Bundle ReportBundle size has no change ✅ |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
test/cartesian/YAxis/YAxis.7362.spec.tsx (2)
44-57: 💤 Low valueConsider advancing timers after rendering.
As per coding guidelines for test files,
vi.runOnlyPendingTimers()should be called after renders when not using thecreateSelectorTestCasehelper to account for Redux autoBatchEnhancer delays. While the tests currently pass (animations are disabled), adding timer advancement would align with best practices and make the tests more robust.⏱️ Suggested pattern
const renderResult = render( <LineChart width={500} height={300} data={data}> <XAxis dataKey="name" /> <YAxis type="number" domain={explicitDomain} allowDataOverflow {...(ticks != null ? { ticks } : {})} {...(tickCount != null ? { tickCount } : {})} /> <Line type="monotone" dataKey="value" stroke="`#8884d8`" isAnimationActive={false} connectNulls /> <ExpectAxisDomain assert={axisDomainSpy} axisType="yAxis" /> </LineChart>, ); +vi.runOnlyPendingTimers(); return {As per coding guidelines: "Call
vi.runOnlyPendingTimers()to advance timers after renders when not usingcreateSelectorTestCasehelper."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/cartesian/YAxis/YAxis.7362.spec.tsx` around lines 44 - 57, After the LineChart render in the test (the render(...) call that assigns renderResult), advance fake timers by calling vi.runOnlyPendingTimers() immediately after rendering to account for Redux autoBatchEnhancer delays; locate the render invocation in YAxis.7362.spec.tsx (the block creating LineChart with XAxis/YAxis/Line/ExpectAxisDomain) and insert a vi.runOnlyPendingTimers() call right after it.
11-31: 💤 Low valueMinor code duplication across test suites.
The
Datumtype,explicitDomain,explicitTicks, and test data constants are duplicated between this unit test file and the VR test suite. While the duplication is minor and the tests serve different purposes, consider whether the sharedDatumtype fromIssue7362Chart.tsxcould be imported here to reduce maintenance burden.♻️ Optional: import shared type
+import type { Datum } from '../../test-vr/tests/Issue7362Chart'; import { ExpectAxisDomain, expectYAxisTicks } from '../../helper/expectAxisTicks'; import { expectLastCalledWith } from '../../helper/expectLastCalledWith'; -type Datum = { - name: string; - value: number | null; -}; - const explicitDomain = [0, 100] as const;Note: The data constants and render helper likely need to remain separate due to the
ExpectAxisDomainspy requirement in unit tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/cartesian/YAxis/YAxis.7362.spec.tsx` around lines 11 - 31, Replace the duplicated Datum type by importing the shared Datum type from Issue7362Chart.tsx and remove the local Datum declaration; keep the existing explicitDomain, explicitTicks, allNullData, and partlyNumericData constants in this test file (they must remain local for the ExpectAxisDomain spy), but update their type annotations to use the imported Datum type so you avoid duplication while preserving test-local data and helpers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/cartesian/YAxis/YAxis.7362.spec.tsx`:
- Around line 44-57: After the LineChart render in the test (the render(...)
call that assigns renderResult), advance fake timers by calling
vi.runOnlyPendingTimers() immediately after rendering to account for Redux
autoBatchEnhancer delays; locate the render invocation in YAxis.7362.spec.tsx
(the block creating LineChart with XAxis/YAxis/Line/ExpectAxisDomain) and insert
a vi.runOnlyPendingTimers() call right after it.
- Around line 11-31: Replace the duplicated Datum type by importing the shared
Datum type from Issue7362Chart.tsx and remove the local Datum declaration; keep
the existing explicitDomain, explicitTicks, allNullData, and partlyNumericData
constants in this test file (they must remain local for the ExpectAxisDomain
spy), but update their type annotations to use the imported Datum type so you
avoid duplication while preserving test-local data and helpers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 149022b7-4997-4296-901c-3ab9cce0f123
⛔ Files ignored due to path filters (12)
test-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-all-null-series-data-1-chromium-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-all-null-series-data-1-firefox-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-all-null-series-data-1-webkit-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-empty-data-1-chromium-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-empty-data-1-firefox-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-empty-data-1-webkit-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-some-numeric-values-1-chromium-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-some-numeric-values-1-firefox-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---explicit-ticks-with-some-numeric-values-1-webkit-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---tickCount-with-all-null-series-data-1-chromium-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---tickCount-with-all-null-series-data-1-firefox-linux.pngis excluded by!**/*.pngtest-vr/__snapshots__/tests/YAxis.7362.spec-vr.tsx-snapshots/YAxis-issue-7362---tickCount-with-all-null-series-data-1-webkit-linux.pngis excluded by!**/*.png
📒 Files selected for processing (4)
.github/skills/vr-test/SKILL.mdtest-vr/tests/Issue7362Chart.tsxtest-vr/tests/YAxis.7362.spec-vr.tsxtest/cartesian/YAxis/YAxis.7362.spec.tsx
|
Tip All tests passed and all changes approved!🟢 UI Tests: 193 tests unchanged |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7379 +/- ##
=======================================
Coverage 89.05% 89.05%
=======================================
Files 548 548
Lines 40575 40575
Branches 5581 5581
=======================================
Hits 36134 36134
Misses 4432 4432
Partials 9 9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
TDD red test documenting the unresolved half of recharts#7362. PR recharts#7379 showed a LITERAL domain ([0,100]) + ticks + allowDataOverflow already renders the ladder on empty/ all-null data. This spec covers a FUNCTION domain (e.g. [0, (dataMax) => finite fallback], or a whole-domain function), which recharts skips when there is no data domain — so the ladder does not render. Uses it.fails: the assertions express the desired behavior and currently throw, so the suite stays green while documenting the gap; they flip to FAILING once recharts invokes a function domain without data, signalling it's time to drop .fails. Refs recharts#7362. Signed-off-by: Nicolas <[email protected]>
… ticks on empty/all-null data (#7384) ## What A single, TDD-style **red** spec — `test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx` — documenting the unresolved half of #7362. **Tests only; no `src/` changes** and no behavior/contract change. ## Context PR #7379 (`YAxis.7362.spec.tsx`) showed the **literal** case already works: `type="number"` + `domain={[0, 100]}` + `ticks` (or `tickCount`) + `allowDataOverflow` renders the `0/25/50/75/100` ladder even when every series value is `null` (or `data={[]}`). This spec covers the case that does **not** work yet: a **function** `domain`. A function bound already decides its own value — e.g. `[0, (dataMax) => (Number.isFinite(dataMax) && dataMax > 0 ? dataMax : 100)]` returns a finite `100` when there is no data. The desired behavior is that recharts invokes that function even when the data domain is empty, so the returned finite bounds resolve the scale and the explicit `ticks` render — exactly like the literal case. ## Current behavior (the gap) recharts skips function domains when there is no data domain: - `numericalDomainSpecifiedWithoutRequiringData` returns `undefined` for any function, and - `parseNumericalUserDomain` only calls the function when `dataDomain != null` (`src/util/isDomainSpecifiedByUser.ts`). With empty/all-null data the data domain is `null`, so the function is never called and the axis renders **0 ticks**. ## Why `it.fails` The three specs assert the **desired** behavior (the ladder renders), which currently throws — so `it.fails` passes and the suite stays green while documenting the gap. They flip to **FAILING** the moment recharts resolves a function domain without data, signalling it's time to drop `.fails` and lock the behavior in. Cases covered: - function upper bound `[0, (dataMax) => …]`, all-null data - function upper bound, empty `data={[]}` - whole-domain function `() => [0, 100]`, all-null data ## Running ``` npm ci npx vitest run --config vitest.config.mts test/cartesian/YAxis/YAxis.7362.derivedDomain.spec.tsx ``` Refs #7362. Related: #7379, #4433, #4426. Signed-off-by: Nicolas <[email protected]>
Tests only. Tried to reproduce #7362 but couldn't.
Summary by CodeRabbit
Documentation
Tests