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

test(component): refactor Counter component tests #658

Conversation

bc-alexsaiannyi
Copy link
Contributor

This PR is aimed to refactor Counter component's tests according to best practices. We take into account recommendations from Kent C. Dodds article. For instance, using container for query-ing elements has been removed. Instead, we replace it with screen.

Why?

the changes are based on GitHub issue and PRs will be open for each component separately.

Testing/Proof

The tests have been successfully run locally.

@bc-alexsaiannyi bc-alexsaiannyi marked this pull request as ready for review December 8, 2021 11:55
@bc-alexsaiannyi bc-alexsaiannyi requested review from a team as code owners December 8, 2021 11:55
Copy link
Contributor

@icatalina icatalina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bc-alexsaiannyi!

Thanks for this PR, looking good, I just added a few comments, let me know what you think about them.

🙇

packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved

const counter = getByDisplayValue('5') as HTMLInputElement;
const counter = screen.getByRole<HTMLInputElement>('textbox');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the type (HTMLInputElement) is necessary anywhere in the file, consider removing it.

packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
Comment on lines 91 to 92
const item1 = screen.getByTestId<HTMLInputElement>('item1');
const item2 = screen.getByTestId<HTMLInputElement>('item2');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast them to HTMLInputElement, all HTMLElements have ids

packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Counter/spec.tsx Outdated Show resolved Hide resolved
@bc-alexsaiannyi
Copy link
Contributor Author

Hey @icatalina. I've added changes. Thank you for going through and adding all your suggestions.

Copy link
Contributor

@icatalina icatalina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a few small comments :)

expect(ref.current).toBe(counter);
render(<Counter value={5} onCountChange={jest.fn()} ref={ref} />);

const input = screen.getByRole<HTMLInputElement>('textbox');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to cast to HTMLInputElement?

const { container } = render(counterMock({ max: 20, ...requiredAttributes }));
render(<CounterMock value={5} />);

const input = screen.getByRole<HTMLInputElement>('textbox');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast to HTMLInputElement:

image


expect(container.querySelector('[class*="StyledError"]')).not.toBeInTheDocument();
expect(screen.queryByText('Error')).not.toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we swap between error and 'Error'?

@chanceaclark
Copy link
Contributor

I'm going to close this since I already did most of it in #1187

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

Successfully merging this pull request may close these issues.

3 participants