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

Created on 5 Apr 2018  路  18Comments  路  Source: enzymejs/enzyme

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

  • [x] shallow
  • [x] mount
  • [ ] render

Version

| library | version
| ---------------- | -------
| Enzyme | 3.3.0
| React | 16.3.0

Adapter

  • [x] 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 ( )
feature request help wanted package 16

Most helpful comment

@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

All 18 comments

@koba04 I was having the same problem, it is fixed by #1592

My workaround is this:

// WrappedInput.js
export const WrappedInput = (props, ref) => <Input {...props} forwardedRef={ref} />

export default React.forwardRef(WrappedInput)
// WrappedInput.test.js
import {WrappedInput} from './WrappedInput'

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

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

You could add a patch as specified in this issue https://github.com/airbnb/enzyme/pull/1513

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

More details here.

@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

@KevinGrandon Looks like your package doesn't include a fix for ForwardRef

There's no need for a separate package; everything in this repo is now published.

1592 will fix it once merged and released.

@ljharb With mount method I still catching this error (Enzyme Internal Error: unknown node with tag 14)

It鈥檚 not released yet, i just merged it an hour ago.

@ljharb Ok. Thanks )

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

No, it should not. This is a new feature, so it would be included in v3.5.0.

@ljharb any prevision to v3.50 release?

Like every release, after it鈥檚 ready, and when time permits.

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

@ljharb i'm not blaming you... you dont need to be defensive. it is just a question :(

i dont know the codebase, but is there anything I can do to help?

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

I'm on 3.10.0. Error persists...

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abe903 picture abe903  路  3Comments

thurt picture thurt  路  3Comments

blainekasten picture blainekasten  路  3Comments

rexonms picture rexonms  路  3Comments

timhonders picture timhonders  路  3Comments