Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 of 10 tasks
Tracked by #1553
DMShamonov opened this issue Apr 5, 2018 · 18 comments · Fixed by #1738
Closed
3 of 10 tasks
Tracked by #1553

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

DMShamonov opened this issue Apr 5, 2018 · 18 comments · Fixed by #1738
Labels
feature request Issues asking for stuff that would be semver-minor help wanted package: react adapter: 16
Projects

Comments

@DMShamonov
Copy link

DMShamonov commented Apr 5, 2018

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 ( )
@ljharb ljharb added help wanted package: react adapter: 16 feature request Issues asking for stuff that would be semver-minor labels Apr 5, 2018
@ljharb ljharb mentioned this issue Apr 5, 2018
41 tasks
@koba04
Copy link
Contributor

koba04 commented Apr 5, 2018

This might be solved by #1592

@petegleeson
Copy link

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

@Hypnosphi
Copy link

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();
});

@joepuzzo
Copy link

You could add a patch as specified in this issue #1513

@KevinGrandon
Copy link

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

More details here.

Oblosys added a commit to Oblosys/react-lifecycle-visualizer that referenced this issue Jun 22, 2018
Cannot be merged yet, since enzyme@3.3.0 currently breaks on a React.forwardRef with an 'Enzyme Internal Error: unknown node with tag 14' (see issue enzymejs/enzyme#1604).
@jquense jquense mentioned this issue Jun 29, 2018
@ljharb ljharb added this to Needs Triage in React 16 via automation Jul 5, 2018
@ljharb ljharb changed the title Enzyme Internal Error: unknown node with tag 14 forwardRef: Enzyme Internal Error: unknown node with tag 14 Jul 5, 2018
@ljharb ljharb moved this from Needs Triage to Refs in React 16 Jul 5, 2018
@FezVrasta
Copy link
Contributor

FezVrasta commented Jul 6, 2018

@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

@Hypnosphi
Copy link

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

@ljharb
Copy link
Member

ljharb commented Aug 10, 2018

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

#1592 will fix it once merged and released.

@DMShamonov
Copy link
Author

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

@ljharb
Copy link
Member

ljharb commented Aug 16, 2018

It’s not released yet, i just merged it an hour ago.

@DMShamonov
Copy link
Author

@ljharb Ok. Thanks )

@sevketufuk
Copy link

sevketufuk commented Aug 16, 2018

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

@ljharb
Copy link
Member

ljharb commented Aug 16, 2018

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

@leobetosouza
Copy link

@ljharb any prevision to v3.50 release?

@ljharb
Copy link
Member

ljharb commented Aug 16, 2018

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.

@leobetosouza
Copy link

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

@RahulDole
Copy link

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

@bdrazen

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues asking for stuff that would be semver-minor help wanted package: react adapter: 16
Projects
React 16
  
Refs
Development

Successfully merging a pull request may close this issue.