Assertion of `_rootDOMNode` doesn't catch `null`
See original GitHub issueI see the following issue testing components that rely on react-textarea-autosize
:
TypeError: Cannot read property 'style' of null
at Window.getComputedStyle (node_modules/jsdom/lib/jsdom/browser/Window.js:371:19)
at calculateNodeStyling (node_modules/react-textarea-autosize/lib/calculateNodeHeight.js:111:22)
at calculateNodeHeight (node_modules/react-textarea-autosize/lib/calculateNodeHeight.js:43:21)
at TextareaAutosize._this._resizeComponent (node_modules/react-textarea-autosize/lib/index.js:78:58)
at TextareaAutosize.componentDidMount (node_modules/react-textarea-autosize/lib/index.js:140:10)
at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:265:25
at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:75:12)
at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:264:11
at CallbackQueue.notifyAll (node_modules/react-test-renderer/lib/CallbackQueue.js:76:22)
at ReactTestReconcileTransaction.close (node_modules/react-test-renderer/lib/ReactTestReconcileTransaction.js:36:26)
It seems like the following check should handle null
: https://github.com/andreypopp/react-textarea-autosize/blob/master/src/index.js#L134
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Assertion of _rootDOMNode doesn't catch null #157 - GitHub
I see the following issue testing components that rely on react-textarea-autosize: TypeError: Cannot read property 'style' of null at Window ...
Read more >Why the non-null assertion operator (!) does not emit actual ...
The point of the non-null assertion operator is to tell the TypeScript compiler that you already know the variable is not null.
Read more >A note on TypeScript non-null assertion operator - Medium
It lets you deliberately ignore an expression's possible null -ness on a case-by-case basis.
Read more >API Reference | Vitest
Returns never , if the value is not a guard function, so you won't be able to chain it with other matchers. asserts...
Read more >Walking the DOM - The Modern JavaScript Tutorial
There's a catch: document.body can be null. A script cannot access an element that doesn't exist at the moment of running.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dimon85
I’ve found the solution here.
Im not convinced at the moment that we should guard against this.
react-test-renderer
chose not to provideref
s automatically, its their API and people should be aware if they chose to use it. OTOH it’s really a shame that this doesnt work out of the box so I might consider adding guards in the future.Also - please use just
enzyme
, its quite a recommended way.@mertkahyaoglu , my solution:
import toJson from 'enzyme-to-json';
import { shallow } from 'enzyme';
it('+++ should render correctly', () => {
const component = shallow(<Textarea
name="description"
placeholder="Description"
/>);
expect(toJson(component)).toMatchSnapshot()
});