When I try to find .value of an input DOM node .instance() returns null.
In enzyme@2* it was very ok with .get(0).
What was in enzyme 2* and worked:
const wrapper = mount(<MyComp>); // input somewhere within tree
const inputNode = wrapper.find('input').get(0);
expect(inputNode.value).toBe('0');
In enzyme 3 this doesn't work. I've tried to do this (which should work by documentation):
const wrapper = mount(<MyComp>);
const inputNode = wrapper.find('input').instance(); // <------ returns NULL
expect(inputNode.value).toBe('0');
Is this a bug or I missed something?
P.S. React is 15.1.0 with enzyme-adapter-react-15.4
UPD: Seems with React 16.5.2 and appropriate Adapter it works
@deser what's the code in MyComp?
Oh, sorry. Here you go:
const wrapper = mount(<div><input value="0" /></div>);
const inputNode = wrapper.find('input').get(0);
expect(inputNode.value).toBe('0');
Try this:
const wrapper = mount(<div><input value="0" /></div>);
const inputNode = wrapper.find('input').getDOMNode();
expect(inputNode.value).to.equal('0');
The same
My test passes in React 16; it fails for you in 15? I'll run the test in CI and verify.
React is 15.1.0 with enzyme-adapter-react-15.4
Here it fails
UPD: Seems with React 16.5.2 and appropriate Adapter it works
Here it works
@deser the tests passed in CI; see this commit.
Perhaps you provided the actual component code - the code in MyComp, not the test code - I could reproduce this?
Is this react 15 wrapper and adpater? Have you installed react 15.1.0?
@deser this is with every version of react from 0.13 through 16 - here's the test run:
https://travis-ci.org/airbnb/enzyme/builds/437735796
I guess to be fair it's with 15.4, not 15.1 - if you upgrade to 15.4 does that fix your issue?
I just decided to not upgrade enzime until we update react up to 16.
Anyway , thanks for your support . Maybe this issue will help others
That's a really poor decision; you'll absolutely need to upgrade to enzyme 3, and get your tests working, before trying to update to react 16.
It would be really helpful if you could try to upgrade to React 15.4 and confirm whether that fixes your issue or not - if it does, then it's a bug in 15.1, and I can reopen this and fix it.
Ok, I'll try and report
Most helpful comment
Here it fails
Here it works