Enforce best practices for testing #2357
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not the biggest expert when it comes to testing components, so I looked up some guidelines and found that there's a lot of things which can be improved in existing unit tests.
See:
Changes:
act(() => {})aroundrender,fireEvent, etc. Which was actually everyactin the code!toHaveValue(),toBeDisabled(),toBeChecked(), etc..mock.calls[0][0]).toBe()withtoHaveBeenCalledWith().getBy*when accessing elements that should be present, andqueryBy*only with.not.toBeInTheDocument();expectFileNameToBechecker which would always pass, as it had noexpectcondition and used aqueryBy(which allows non-existance). It now uses anawait find.Not Fixed:
contributor_docs/testing.md, but this entire document could use a review.// eslint-disable-next-line testing-library/no-render-in-setupin theclient/index.integration.test.jsxfile rather than fixing it.testing-library/render-result-naming-conventionbecause it doesn't like the way that we writeconst props = renderComponent();in theToolbarandFileNodetests.@testing-library/user-eventlibrary, as it caused errors.I have verified that this pull request:
npm run lint)npm run test)developbranch.Fixes #123