-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Invalid Test Case Results from Enzyme's.find() - Returns inconsistent Results for <DatePicker /> component in exclude_times_test.test.js #4317
Invalid Test Case Results from Enzyme's.find() - Returns inconsistent Results for <DatePicker /> component in exclude_times_test.test.js #4317
Comments
@martijnrusschen , can you please assign this issue to me. I'll work on it. |
Done |
We'd like to remove enzyme from the test suite so if you're rewriting tests let's try avoiding more enzyme usage. |
In the exclude_times_test.js file, the following modifications were made to improve the test case: 1. Added the 'open' prop to the <DatePicker /> component to ensure that it is open and its children can be tested. 2. Corrected the call to 'setTime' by providing the correct parameter format, { hour: x, minute: x }, instead of { hours: x, minutes: x }. 3. Replaced the assertion using '.not.toBeNull()' with '.toHaveLength(4)' when using '.find()'. This change makes the assertion more specific and reliable, ensuring that the test case passes only when it should. These updates enhance the accuracy and reliability of the test case in the exclude_times_test.js file. Closes Hacker0x01#4317
This commit updates the test case in exclude_times_test.js from using Enzyme to using @testing-library/react as requested by @martijnrusschen on [the issue Hacker0x01#4317](Hacker0x01#4317 (comment))
Thank you for assigning the issue to me @martijnrusschen. As per your request, I fixed the test cases and also migrated the file to use react-testing-library instead of enzyme. Kindly review my PR and let me know if any changes required. |
…iour Fix #4317: Fix Enzyme Test file in exclude_times_test.js and migrate it to use @testing-library/react
Problem
In the
exclude_times_test.test.js
file, we have encountered an issue when using Enzyme's.find()
method in conjunction withmount()
to render a<DatePicker />
component and querying elements by class. The.find()
method is returning an empty wrapper even when the specified class does not exist, which is leading to inconsistencies in our test results and making it challenging to determine the validity of our test cases.In the above screenshot, the test case should fail, as the
<DatePicker />
is not opened or inline, it won't render any date or time, hence the test case would fail obviously. But as we're expectingexpect(datePicker.find('xxx')).not.toBeNull()
the test case is getting ignored.So, in this file, I found 2 issues
<DatePicker />
is not opened, hence the test case fails.not.toBeNull
instead of checking specific assertion like length checkI also found one another important bug, that is related to the use of
setTime
helper while settingexcludeTimes
propIf you notice the above screenshot, we're passing invalid argument to the
setTime
helper. For example, instead ofhour
, we are passinghours
and instead ofminute
we're passingminutes
.Proposed Solution
setTime
call<DatePicker />
component to test it, by passing theopen
proptoHaveLength(4)
instead of using.not.toBeNull
The text was updated successfully, but these errors were encountered: