question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assertion of `_rootDOMNode` doesn't catch `null`

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
Andaristcommented, Aug 29, 2017

@dimon85

I’ve found the solution here.

    const tree = renderer.create(
      <Textarea
        name="description"
        placeholder="Description"
      />,
      { createNodeMock: () => document.createElement('textarea') }
    ).toJSON();

Im not convinced at the moment that we should guard against this. react-test-renderer chose not to provide refs 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.

2reactions
dimon85commented, Oct 31, 2017

@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() });

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found