Engineering Journal
Table Formatter
Table Formatter

The feature existed in the DOM and nobody could see it

2026-07-16

TLDR

I shipped a "create new table" feature that passed all seven of its DOM tests and rendered nothing on screen. The wrong assumption: if the elements exist in the tree with the right structure, the feature works. jsdom does not apply stylesheet layout, so a display: none inherited from a CSS class was invisible to every test I wrote.

The assumption that seemed reasonable

The feature appends a card into a container: a header button, a panel div, and an empty table with a fresh ID inside. I tested it headlessly with jsdom and jQuery, loading the real production source files rather than a reimplementation. The assertions were thorough by structure-testing standards:
ok   table appended (3 total)
ok   new id is t-4 (max+1, no collision)
ok   3 body rows + 1 header row = 4 tr
ok   4 header columns
ok   3x4 = 12 body cells
ok   currentTable points to new table
7 passed, 0 failed

Structure, counts, identity, state pointers. If you had shown me that output I would have called the feature done. I did call it done.

When it failed

The user opened the app, clicked the button, and reported: "it creates the wrapper but it doesn't create the table." The accordion header appeared. The table did not.

The table was there. Fifteen rows of it, sitting in the DOM exactly as the tests described.

What made the report disorienting is that half the feature visibly worked. The header button rendered, was clickable, and toggled. If the append had failed outright I would have suspected the sanitizer or a selector typo immediately. A partially visible feature sends you hunting in the wrong layer: I re-read the HTML construction and the ID allocation before it occurred to me to check computed styles on the panel.

What was actually wrong

The panel class the card uses is collapsed by default in the app's stylesheet:
.panel {
    display: none;
}

Panels are accordion bodies. The only code that opens them runs once during app initialization, walking existing panels and showing the active ones. My feature appended a new panel after initialization, so nothing ever showed it. A second mechanism compounded the invisibility: the ruler renderer skips any table whose bounding width is zero, so even the table's decorations declined to render.

jsdom could not have caught this. It parses CSS but does not compute layout or apply stylesheet-driven visibility, which is a documented design boundary, not a bug. Every element I asserted on existed. Existence was the wrong property to assert.

There is a subtler version of the same mistake in how I chose the test harness. I was proud that the harness loaded the real production source files instead of a reimplementation, and that pride was earned for the data layer: it caught genuine index-math errors during development. But loading real JS is only half of the real app. The other half is the stylesheet, and the harness never loaded it at all. A test rig that faithfully executes your logic against an environment missing one whole subsystem will validate everything except the failures that subsystem causes.

What got deleted

Nothing, which is its own lesson. The fix was one added line, not a redesign:
container.append(cardHtml);
// panels default to display:none; a freshly drawn table must be visible
$(newTable).closest('.panel').show();

The deleted thing was my confidence in the test suite's coverage claim, not any code.

Evidence

The before state is reproducible: append the card markup into the container without the .show() call, and getBoundingClientRect().width on the new table returns 0 in a real browser while all seven structural assertions still pass in jsdom. The CSS rule above is quoted verbatim from the app's stylesheet, and the test output is pasted from the actual harness run.

What replaced it

The tests stayed, because they do catch real bugs in the grid math and ID allocation. What changed is the claim I let them make. Structure tests now gate the data layer only, and anything user-visible gets a real browser pass before I report it working. The report to the user changed too: "verified in jsdom, visibility unverified" instead of "done."

The cheap middle ground, if a full browser pass is not available, is to assert the negative you actually care about: after appending, check that no ancestor of the new element carries a class whose stylesheet rule hides it. That is still a structure test, but it encodes the one visibility fact that bit me, and it would have failed loudly here.

The lesson

A headless DOM test proves an element exists, not that anyone can see it. Any assertion about visibility needs a rendering engine, or it is an assumption wearing a test's clothing.
Read this post in the full Engineering Journal →