Skip to content

Invalid Test Case Results from Enzyme's.find() - Returns inconsistent Results for <DatePicker /> component in exclude_times_test.test.js #4317

@balajis-qb

Description

@balajis-qb

Problem
In the exclude_times_test.test.js file, we have encountered an issue when using Enzyme's .find() method in conjunction with mount() 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.

image

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 expecting expect(datePicker.find('xxx')).not.toBeNull() the test case is getting ignored.

So, in this file, I found 2 issues

  1. <DatePicker /> is not opened, hence the test case fails
  2. Using .not.toBeNull instead of checking specific assertion like length check

I also found one another important bug, that is related to the use of setTime helper while setting excludeTimes prop
image

If you notice the above screenshot, we're passing invalid argument to the setTime helper. For example, instead of hour, we are passing hours and instead of minute we're passing minutes.

Proposed Solution

  • Fix the setTime call
  • Open the <DatePicker /> component to test it, by passing the open prop
  • Use .toHaveLength(4) instead of using .not.toBeNull

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions