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

chore: add tests for checkbox #121

Merged
merged 1 commit into from
Mar 11, 2024
Merged

chore: add tests for checkbox #121

merged 1 commit into from
Mar 11, 2024

Conversation

markw-deriv
Copy link
Contributor

Add some unit tests for the Checkbox component.

<Checkbox name="test-checkbox" label="Test Checkbox" labelClassName="custom-label-class" readOnly />
);

const checkboxWrapper = screen.getByLabelText('Test Checkbox')?.parentElement?.parentElement;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was quite hard to test, which hints that the implementation might not be great.

Copy link

cloudflare-workers-and-pages bot commented Mar 7, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b14bd2
Status: ✅  Deploy successful!
Preview URL: https://c44240bd.deriv-ui.pages.dev
Branch Preview URL: https://add-tests-for-checkbox.deriv-ui.pages.dev

View logs

test('triggers onChange event when clicked', () => {
const handleChange = jest.fn();
render(<Checkbox name="test-checkbox" onChange={handleChange} />);
fireEvent.click(screen.getByRole('checkbox'));
Copy link
Contributor

Choose a reason for hiding this comment

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

just out of curiosity 🤔
would it be better to use userEvent ? or in this case it doesn't make any difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah absolutely. Thanks Shayan. Also switched that screen. to using the result from the render, which I find more pure.

@markw-deriv markw-deriv force-pushed the add-tests-for-checkbox branch from 1836373 to 3b14bd2 Compare March 8, 2024 06:56
@shayan-deriv shayan-deriv merged commit 32e9cec into main Mar 11, 2024
2 checks passed
@shayan-deriv shayan-deriv deleted the add-tests-for-checkbox branch March 11, 2024 03:24
Copy link

🎉 This PR is included in version 1.10.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants