DEV Community

Discussion on: I Went to Write Two Tests and Ended Up Fixing the App

Collapse
 
maciek_chmura_building profile image
Maciek Chmura •

The fixture detail is the part I'd underline. Every fake post had reportedBy: [], so the mocks only knew the shape someone typed by hand. One habit that helps: build unit fixtures by calling the same create path the app uses, or keep one fixture with the optional fields missing on purpose. A quick count of real documents without reportedBy also tells you if other code paths hit the same trap. On the double toast, I'd check whether both the mutation's onError and a global error link show it. Did you find which one fires twice?

Collapse
 
wamzii profile image
cynthia wahome •

Good questions. Here's what I found.

Fixtures. My PRs have both kinds. #686 added a unit test with a post that has no reportedBy key at all, kept on purpose as the regression for this bug, and #698's E2E specs create their posts through the real addPost mutation. The older component unit tests still use a hand-typed fixture with reportedBy: [], so your point holds there, and that's how the bug stayed hidden.

Your count. New posts now get reportedBy: [], but approvedBy, rejectedBy and bookmarkedBy are missing on all 50 of my local posts. I approved, rejected and saved a post with those lists missing, and all three worked, so the ?? [] reads hold up.

The double toast. You called it: the component's catch and the global error link both show it, and switching either off leaves exactly one toast. I raised it with the maintainers so they can decide which should own it.

Count of posts missing each list: reportedBy is covered, the other three are missing on all 50

Terminal output: 50 posts in total, 0 missing reportedBy, and 50 each missing approvedBy, rejectedBy and bookmarkedBy

The double toast: the same error shown twice (Reject 1 and Saved confirm those clicks worked)

Two identical red toasts reading "You have already reported this post"; the post shows Reject 1 and Saved