-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add tests for new Disclosure component and refactor existing tests. #18
Conversation
This commit adds tests for the new Disclosure component, updates existing tests to account for the Disclosure component, and refactors existing tests to be better organized.
74fe78a
to
c2ef0c9
Compare
Codecov Report
@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 79.16% 88.19% +9.02%
==========================================
Files 10 10
Lines 144 144
Branches 18 18
==========================================
+ Hits 114 127 +13
+ Misses 30 17 -13 see 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
expect(screen.queryByTestId('submit-button')).not.toBeInTheDocument(); | ||
expect(screen.queryByTestId('close-button')).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: 'Clear' })).not.toBeInTheDocument(); | ||
const assertSidebarContainerElements = (inDOM) => { |
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.
I wrote a number of functions to check for elements of a particular component in the DOM. The inDOM
parameter determines whether the elements should or should not be in the DOM.
|
||
// assert that UI elements in the sidebar are not in the DOM | ||
assertSidebarElementsNotInDOM(); | ||
describe('Toggle', () => { |
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.
I broke out the tests per component and put them in their own suite.
const input = screen.getByRole('textbox'); | ||
await user.type(input, userMessage); | ||
beforeEach(async () => { | ||
jest.spyOn(api, 'default').mockRejectedValue(new Error('sample API error')); |
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.
Instead of simulating an error state by specifying it in the Redux store, I decided to, instead, mock out the API to return an error. This has the benefit of testing out the action creators and everything that should happen before the Redux store is updated and is a more real-world test because it's how the user would experience the page. Let me know if you disagree with this refactor.
The Disclosure component was refactored in this PR and it has its own tests. Closing the PR due to obsolescence. |
Description
This pull request adds tests for the new Disclosure component, updates existing tests to account for the Disclosure component, and refactors existing tests to be better organized.