Closed Bug 1804786 Opened 2 years ago Closed 2 years ago

Enzyme assertions in unit tests are always passing

Categories

(Firefox :: Messaging System, defect)

defect

Tracking

()

RESOLVED FIXED
110 Branch
Tracking Status
firefox110 --- fixed

People

(Reporter: aminomancer, Assigned: aminomancer)

References

Details

Attachments

(1 file)

Many of our React unit tests have this form assert.ok(wrapper.find(selector)) (the wrapper is from enzyme). But that is always going to pass unless the selector is not a valid string, because ReactWrapper::find always returns a ReactWrapper, it's just an empty wrapper if nothing was found. The result is that our unit tests can't catch many regressions, because these assertions always pass for any string value.

Instead, I think we should use assert.ok(wrapper.find(selector).exists())

Hopefully most of our tests will still work after fixing this issue, though some of the tests are only passing because of this issue. For example, this test looks like it's for an old version of the StepsIndicator component. There is no currentScreen property, and the StepsIndicator component itself does not render a <div class="steps"/> element, it just returns the children. The actual div.steps is the parent element. So tests like this will need to be updated to account for the current source code.

Bug 1778409 intends to ditch Enzyme, but I would still like to fix this in the meantime.

Modify the enzyme assertions in unit tests so they can fail when
regressed. Update the same tests since now they would fail otherwise.
One of them also required fixing a bug in MSLocalized.jsx.

Assignee: nobody → shughes
Status: NEW → ASSIGNED
Pushed by shughes@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f58c8037ccc8
Fix enzyme unit tests. r=mviar
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 110 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: