InlineCheckbox sets indeterminate of null in snapshot testing
See original GitHub issueWhat package(s) are you using?
-
carbon-components@10.9.3
-
carbon-components-react@7.9.3
-
react-test-renderer@16.13.0
Detailed description
Describe in detail the issue you’re having.
While snapshot testing DataTable
with batch actions with Jest and react-test-renderer
, the react-test-renderer
snapshot test fails with the following error:
TypeError: Cannot set property 'indeterminate' of null
at InlineCheckbox.componentDidMount (components/InlineCheckbox/InlineCheckbox.js:70:36)
I believe this is occurring due to the follow lifecycle method:
In a JSDOM rendered environment, the this.inputNode
ref is null, yet we are attempting to set indeterminate
on it.
This issue has arisen in other UI libraries that have handled input elements in snapshot testing. Their solution was to add a check to ensure that the ref was non-null before setting indeterminate. I don’t believe there should be a situation in a live web application where the input ref is null, but specifically in react-test-renderer
snapshot testing this comes up, and the error prevents generating snapshots.
Related issue: https://github.com/palantir/blueprint/issues/3408#issuecomment-471852467
Is this issue related to a specific component?
InlineCheckbox (and any component that consumes it)
What did you expect to happen? What happened instead? What would you like to see changed?
I expected to see a snapshot generated using react-test-renderer
, but instead snapshot generation was prevented due to the above error.
What browser are you working in?
Node.js (JSDOM)
Steps to reproduce the issue
- Create a react component using DataTable with batch actions
- Write a snapshot test with
react-test-renderer
- Observe the error in the test that prevents snapshot generation
Please create a reduced test case in CodeSandbox
Reproducible demo here: https://codesandbox.io/s/indeterminate-carbon-jest-failing-so4g7
(To view the failing test, select the Tests
tab on the right side of the page)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@emyarod yes I can look into zipping that up
any updates @repjarms ?