Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MichaelRoytman
Copy link
Member

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.

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.
@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #18 (c2ef0c9) into main (fe1e428) will increase coverage by 9.02%.
The diff coverage is n/a.

@@            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) => {
Copy link
Member Author

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', () => {
Copy link
Member Author

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'));
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant