Skip to content
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

Assertion of _rootDOMNode doesn't catch null #157

Closed
kevinehosford opened this issue Jun 13, 2017 · 16 comments
Closed

Assertion of _rootDOMNode doesn't catch null #157

kevinehosford opened this issue Jun 13, 2017 · 16 comments

Comments

@kevinehosford
Copy link

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:/andreypopp/react-textarea-autosize/blob/master/src/index.js#L134

@Andarist
Copy link
Owner

What version of the library do u use?

@kevinehosford
Copy link
Author

v5.0.6

@Andarist
Copy link
Owner

Could u share repository with reproduced issue? It would certainly speed up the fix for this.

@Andarist
Copy link
Owner

@kevinhos any updates on this?

@kevinehosford
Copy link
Author

I apologize. I've been struggling to find time to put together an example.

@vladinator1000
Copy link

vladinator1000 commented Jul 31, 2017

Not sure if this is related, but works fine for me on 4.0.5, when I tried upgrading to 5.1 I got this error:
"TypeError: Cannot read property 'getHostNode' of null"

When doing this (using variables from props):

<Textarea
	value={value}
	onChange={onChange}
	type={type}
	name={field}
	placeholder={placeholder}
	ref={componentReference => this._input = componentReference}
/>

@Andarist
Copy link
Owner

Andarist commented Aug 1, 2017

@savovs could u reproduce on something like codesandbox.io ?

@dimon85
Copy link

dimon85 commented Aug 28, 2017

@Andarist Hi, I have the same issue, when testing with jest (add snapshot)
v. 5.1.0
it("Should render Textarea correctly", () => { const tree = renderer.create( <Textarea name="description" placeholder="Description" /> ).toJSON(); expect(tree).toMatchSnapshot(); });
Get the same error TypeError: Cannot read property 'style' of null,
Other tests pass well.

@Andarist
Copy link
Owner

@dimon85 could u share a repository with reproduced issue and minimal setup?

@dimon85
Copy link

dimon85 commented Aug 28, 2017

I am working in private repository, i need more time to create new repository.

@Andarist
Copy link
Owner

Sure thing, if I find some time I might do that myself, but lately I'm really busy and that's why I'm asking for a little bit of help here :)

@dimon85
Copy link

dimon85 commented Aug 29, 2017

@Andarist Hi, take a look this repo https:/dimon85/textarea-test
Thanks.

@Andarist
Copy link
Owner

@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.

@Andarist
Copy link
Owner

@savovs @kevinhos Was your setup the same? jest + react-test-renderer?

@mertkahyaoglu
Copy link

@Andarist I'm using jest and react-test-renderer. I got the same error trying to write a snapshot test.

@dimon85
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants