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

Fix #5038: Enhance test case querySelector/querySelectorAll reliability with ensuring element existance #29

Merged
merged 24 commits into from
Aug 30, 2024

Conversation

balajis-qb
Copy link
Collaborator

Closes Hacker0x01#5038

Issue
Currently in our project test cases, in many places we followed a format like container.querySelector('...') ?? new HTMLElement() or container.querySelectorAll('...') ?? []. In most of these cases, we wrote a test case on top of it. But this way of using a fallback null elements won't help us to test the actual cases, as missing elements are replaced by new ones, allowing tests to pass whey they shouldn't.

Contribution
To address this, a new utility function has been developed that throws an error if the querySelector result is null or if querySelectorAll returns an empty array. This ensures that missing elements are caught early and improves the reliability of our test cases.

This is just a test case update and it won't affect the source code, but just the way we're currently checking null elements. This PR mainly focus to replace the code like container.querySelector('...') ?? new HTMLElement() or container.querySelectorAll('...') ?? [] with safer way to access the elements.

Screenshots

image

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

Balaji Sridharan added 24 commits August 19, 2024 15:34
…afeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
… safeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…All with safeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…h safeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…l with safeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…afeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…ySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…afeQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…Selector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…feQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…eQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…QuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…feQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…QuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…QuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…feQuerySelector/safeQuerySelectorAll to ensure element existence

- This change prevents tests from passing with unexpected null elements, enhancing test reliability and catching potential issues earlier.

Closes Hacker0x01#5038
…be null

- As the safeQuerySelector automatically throws if the element is not found, additionally checking for null value is not needed
… the safeQuerySelector automatically throws an error if the element is not found
…und element is less than the minExpected param
…ed no of elements and remove the redundant throw error logic
@balajis-qb balajis-qb merged commit 000bbd9 into main Aug 30, 2024
3 of 4 checks passed
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.

Enhance test case querySelector/querySelectorAll reliability with ensuring element existance
1 participant