Skip to content

test(data): cover the null and undefined x the same guard un-breaks - #5281

Merged
junedchhipa merged 1 commit into
apexcharts:mainfrom
aron-intframe:test/null-undefined-x-assertion
Aug 31, 2026
Merged

junedchhipa merged 1 commit into
apexcharts:mainfrom
aron-intframe:test/null-undefined-x-assertion

Conversation

@aron-intframe

Copy link
Copy Markdown
Contributor

Follow-up to #5279, tests only, no src/ change.

You pointed out that the guard there also un-breaks null and undefined x values, and that it was the one thing in the PR with no test on it. You were right on both counts, and it is the more common case: a gap in a data set is spelt null far more often than a Date is built from garbage.

Reverting the guard on this branch, all three new assertions go red:

AssertionError: expected [Function] to not throw an error but
  'TypeError: Cannot read properties of null (reading 'replace')' was thrown
AssertionError: expected [Function] to not throw an error but
  'TypeError: Cannot read properties of undefined (reading 'replace')' was thrown

Tests 5 failed | 3 passed (8) with the guard reverted, 8 passed with it in place. The 5 are the 2 from #5279 plus these 3, so neither set is vacuous.

What the render does, measured rather than assumed. Without the guard, [{x: 1}, {x: null}, {x: 3}] gives 0 .apexcharts-line paths and 0 x axis labels. With it, 1 path and labels 1, 2, 3.

Full unit suite: 136 files, 3257 tests, 0 failures. npm run lint clean. npm run typecheck still 23 errors, all pre-existing in Drilldown.js. prettier --write on the spec touched only one block this PR adds, and that reformat is included.

The guard in apexcharts#5279 was written for an invalid Date, but the line it
replaced threw on anything without .replace(). null and undefined go
through the same path, and a gap in a data set is spelt null far more
often than a Date is built from garbage: without the guard,
[{x: 1}, {x: null}, {x: 3}] renders nothing at all.

Three assertions, all red when the guard is reverted:
isValidDate answers false instead of throwing, the points either side
of the gap keep their x, and the render survives an undefined x.

Co-Authored-By: Claude Opus 5 <[email protected]>
@junedchhipa

Copy link
Copy Markdown
Contributor

Checked this the same way: 8 passing as it stands, and 5 failing with 3 passing once I take the guard back out, which is what you reported. The three new ones are earning their place, and the suite numbers match on the nose (136 files, 3257 tests).

You are right that null is the case people actually hit, so it is good to have it pinned down.

One thing to be aware of rather than change: expect(seriesX).toEqual([1, null, 3]) locks in the null sitting raw in seriesX, which is the leftover I mentioned on #5279, a non-numeric value in an array the rest of the code reads as numbers. It works well as a regression guard. Just keep in mind that if we ever tidy that up and coerce it, this is the assertion that moves.

Nothing blocking.

@junedchhipa
junedchhipa merged commit b22122c into apexcharts:main Aug 31, 2026
5 checks passed
@aron-intframe

Copy link
Copy Markdown
Contributor Author

Agreed on the leftover, and I measured what it does downstream today rather than leave it as a note. A scratch spec rendering [{x: 1}, {x: null}, {x: 3}] and logging the globals gives, on both axis types:

CATEGORY seriesX = [[1,null,3]]
CATEGORY minX = 1 maxX = 3
CATEGORY labels = [1,2,3]
NUMERIC seriesX = [[1,null,3]]
NUMERIC minX = 1 maxX = 3
NUMERIC labels = [1,2,3]

So the raw null is benign in the min/max and label paths right now: it does not get read as 0 anywhere I could observe, and minX stays 1 on a numeric axis too. One near-miss I should mention so nobody chases it later: in that run the numeric-axis line d came out as M 0 NaN, which looked like the null leaking into pixel math, but a control chart with x: 1, 2, 3 and no null (and another with a null y) produces the same M 0 NaN under jsdom, where the container has zero layout dimensions. That is a test-environment artifact, not the leftover, so I am not claiming it as a finding.

And yes, expect(seriesX).toEqual([1, null, 3]) is exactly the assertion that moves if a coercion pass ever tidies this up. That is what I want from it: it pins today's contract, and whoever changes it gets one red test pointing at the array that shifted instead of a silent behaviour change. Happy to update it alongside that work when it comes.

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