enzyme: forwardRef: Enzyme Internal Error: unknown node with tag 14

Current behavior

After update React to 16.3.0 version and use forwardRef, my tests is broken.

Component that uses forwardRef now exports as:

export default forwardRef((props, ref) => (
  <Input {...props} forwardedRef={ref} />
));

and test is:

test('with `id` prop', () => {
    const output = shallow(<Input id={id} />);

    expect(renderToJson(output)).toMatchSnapshot();
  });

throw error is: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was 'object'.

But if I use render method this error doesn’t happened.

When I use mount method with test is:

test('value state is changed', () => {
    const value = 'New value';
    const wrapper = shallow(<Input />);

    wrapper.setProps({ value });
    expect(wrapper.state().value).toEqual(value);
  });

I catch error is: Enzyme Internal Error: unknown node with tag 14

Expected behavior

Your environment

API

  • shallow
  • mount
  • render

Version

library version
Enzyme 3.3.0
React 16.3.0

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 26
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@KevinGrandon I’m trying your package but I still get the same error, are you sure it ships the patch needed for the forwardRef feature?

I don’t see the node listed in the allowed nodes list: https://github.com/KevinGrandon/enzyme/blob/master/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js#L25-L34

Looks like the new version v3.5.0 is released! And that suddenly made my life easier! Last Friday night I had checked it and it wasn’t released, and today Monday morning surprise that its released. Thanks a lot @ljharb

Like every release, after it’s ready, and when time permits.

It hasn’t even been a full day yet. I do sleep, in case that isn’t apparent.

@ljharb so 3.4.2 should solve this problem? I’m using 3.4.2 and I still got the same error.

I’m on 3.10.0. Error persists…

Edit: Also had to update enzyme-adapter-react-16. All good now.

Best way to fix this currently: yarn add --dev enzyme-adapter-react-16@npm:enzyme-react-adapter-future.

More details here.