Enzyme: nodes[0] changed to use getElements() but Test still Fails

Created on 22 Oct 2017  路  4Comments  路  Source: enzymejs/enzyme

I upgraded to enzyme 3. Here are the steps I did to upgrade:

  • installed enzyme, now ^3.1.0, prior to upgrading it was ^2.4.1
  • installed:enzyme-adapter-react-15.4
    npm install -D enzyme-adapter-react-15.4
  • we're running the following versions for react packages:
    react ^15.2.1
    react-dom ^15.0.1

After 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?

v3 expected difference

Most helpful comment

ah - you're not calling getElements. Try getElements()[0] instead

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blainekasten picture blainekasten  路  3Comments

SandroMachado picture SandroMachado  路  3Comments

blainekasten picture blainekasten  路  3Comments

modemuser picture modemuser  路  3Comments

potapovDim picture potapovDim  路  3Comments