-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incremental UI Tests #3 #82
Conversation
037ad53
to
ddf4ab3
Compare
expect(screen.getByText(/Delete this Draft/)).toBeDefined(); | ||
}); | ||
|
||
it('deletes a draft from Redux when the delete button is clicked', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where userEvent
as a library is really nice. I think this test is really easy to understand, and mirrors how a user would interact with the table. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice, great demonstration of the value of that library! I imagine writing this test otherwise would be so complicated that I would have probably suggested we forget automating it (and just test manually)
userEvent.click(screen.getByText(/Delete this Draft/)); | ||
|
||
// Wait for antd to render the confirm modal, then click Yes | ||
await waitFor(() => screen.getByText('Yes')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, you could combine lines 69 and 70, but according to Kent himself, it's an antipattern:
waitFor is intended for things that have a non-deterministic amount of time between the action you performed and the assertion passing. Because of this, the callback can be called (or checked for errors) a non-deterministic number of times and frequency (it's called both on an interval as well as when there are DOM mutations). So this means that your side-effect could run multiple times!
visible={props.visible} | ||
onCancel={props.onClose} | ||
footer={props.footer} | ||
destroyOnClose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only line that changed. Keeping the modal in the DOM is wasteful and confuses the test runner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
Thanks!
expect(screen.getByText(/Delete this Draft/)).toBeDefined(); | ||
}); | ||
|
||
it('deletes a draft from Redux when the delete button is clicked', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice, great demonstration of the value of that library! I imagine writing this test otherwise would be so complicated that I would have probably suggested we forget automating it (and just test manually)
visible={props.visible} | ||
onCancel={props.onClose} | ||
footer={props.footer} | ||
destroyOnClose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
Thanks!
* App tests * Add scaffolding for useIsMounted * Ignore .js, .jsx, and other CRA files * Action creator tests * renderCommaSepList tests * removeMiddleAuthorsTest * shortenAuthors test * shortenTableString * getTagColor test * isDOI test * markdown test * shhhh is okay * self review feedback * DraftsRedux test * Woohoo! A Redux test * finish drafts tests Co-authored-by: Eshed Margalit <eshedmargalit@users.noreply.github.com>
Review #81 first! Once that's done, change this base branch to
react-ts
(or whatever the mainline is at that point).🚨 Important! This fixes a legitimate bug with
goBack
vs.back
. Apparently there's an incompatibility betweenreact-router-dom
andhistory@5
, so I downgraded to 4. Here's the literature on thatThis also fixes a silly bug where the
reduxRender
wouldn't properly nest Routes in a<Switch />