I upgraded to enzyme 3. Here are the steps I did to upgrade:
^3.1.0, prior to upgrading it was ^2.4.1enzyme-adapter-react-15.4npm install -D enzyme-adapter-react-15.4^15.2.1^15.0.1After upgrading this test fails, but I can't find getElement(). Am I missing an upgrade somewhere?
it('returns a tab item as an image', () => {
const tabImage = <img src="" alt="" className="tab-item-image" />;
const tabItem = shallow(<TabItem store={fakeStore()} content={tabImage} />)
.find('.tab-item').find('.tab-item-image');
expect(tabItem.nodes[0]).to.deep.equal(tabImage);
});
Error
Attempted to access ShallowWrapper::nodes, which was previously a private property on
Enzyme ShallowWrapper instances, but is no longer and should not be relied upon.
Consider using the getElements() method instead.
Tried this but this test which was passing prior to upgrading to 3.0 still fails
expect(tabItem.getElements[0]).to.deep.equal(tabImage);
Error
AssertionError: expected undefined to deeply equal { Object ($$typeof, type, ...) }
so how do I change this syntax to get this working again?
If you're using react 15.2, you have to use react-dom 15.2 also - does that fix it?
thanks!
hmm ok did that. It still same error AssertionError: expected undefined to deeply equal { Object ($$typeof, type, ...) }
let me investigate a little more on my end and I'll come back to this.
ah - you're not calling getElements. Try getElements()[0] instead
solved:
it('returns a tab item as an image', () => {
const tabImage = <img src="" alt="" className="ft-tab-item-image" />;
const tabItem = shallow(<TabItem store={fakeStore()} content={tabImage} />).find('.ft-tab-item');
const image = tabItem.find('.ft-tab-item-image');
expect(image.getElement(0)).to.deep.equal(tabImage);
});
but yes, in general you caught a dumb mistake...thank you!
Most helpful comment
ah - you're not calling getElements. Try
getElements()[0]instead