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

Enzyme Internal Error: unknown node with tag 14 #1717

Closed
karolisgrinkevicius opened this issue Jul 18, 2018 · 19 comments
Closed

Enzyme Internal Error: unknown node with tag 14 #1717

karolisgrinkevicius opened this issue Jul 18, 2018 · 19 comments

Comments

@karolisgrinkevicius
Copy link

karolisgrinkevicius commented Jul 18, 2018

Getting Enzyme Internal Error: unknown node with tag 14 where mount is used on cloned element node. For instance:

...
 mount(React.cloneElement(node))
...

Update
After grid-styled reverted to 4.1.1 seems to be working fine.

Versions

  • grid-styled 5.0.2 ☢️
  • styled-system 3.0.1
  • react 16.4.1
  • jest 23.4.1
  • enzyme 3.3.0
  • enzyme-adapter-react-16 1.1.1
  • enzyme-react-intl 2.0.0
  • enzyme-to-json 3.3.4
@ljharb
Copy link
Member

ljharb commented Jul 19, 2018

Hmm, that's a new one, thanks. I'm not sure if that's an issue confined to React 16 or not - it's possible that nobody's ever tried to directly mount or shallow-render a cloned element before :-)

@ljharb ljharb added this to Needs Triage in React 16 via automation Jul 19, 2018
@karolisgrinkevicius
Copy link
Author

At least I’ve tried and it was actually working fine before. 👌🏻

@AdamZaczek
Copy link

AdamZaczek commented Jul 27, 2018

I also have this issue when using grid-styled 5.0.2

@ljharb
Copy link
Member

ljharb commented Jul 27, 2018

@karolisgrinkevicius can you be more specific on "before"? do you mean in enzyme 2, or in react 15 with enzyme 3, or in an earlier version of the react 16 adapter?

@karolisgrinkevicius
Copy link
Author

@ljharb as the icon after grid-styled reveals in my post it's basically what I'm talking about.

@ljharb
Copy link
Member

ljharb commented Jul 27, 2018

ah - right :-) that implies that grid-styled updated to use fragments; as opposed to implying that enzyme has a regression around mounting fragments.

@karolisgrinkevicius
Copy link
Author

@ljharb could you please be more specific? I'm actually looking for the concrete solution to solve this.

@ljharb
Copy link
Member

ljharb commented Jul 27, 2018

@karolisgrinkevicius sure! basically, it's clear that "latest enzyme" can't mount cloned elements. It's clear that you don't run into this problem with grid-styled v4, only with v5 - but that doesn't relate to enzyme, since v4 probably isn't using cloned elements at all. What would relate to enzyme, is if grid-styled v5 works with any version of enzyme - which I suspect it does not.

@karolisgrinkevicius
Copy link
Author

I actually created an issiue in grid_styled as well to make sure this could be solved a bit quicker. If it’s nothing that enzyme can do with you can probably close this issue. Thank you for the clarification @ljharb ! 👍🏻

@ljharb
Copy link
Member

ljharb commented Jul 28, 2018

We should be able to mount cloned elements.

@ljharb
Copy link
Member

ljharb commented Jul 28, 2018

I just realized this probably has nothing to do with cloning; can you try to mount node itself? Can you share more of the test code from the OP?

@karolisgrinkevicius
Copy link
Author

@ljharb please see the code below to reproduce this issue using grid-styled@5. The code below simply does mounting with providers to avoid a lot of mocking data in components specs.

import * as React from 'react';
import { createProvider, Provider as ReduxProvider } from 'react-redux';
import { ThemeProvider } from 'styled-components';
import * as R from 'ramda';
import { shallow, mount } from 'enzyme';
import configureStore from 'redux-mock-store';

import { theme } from 'theme'; // locally defined theme
import rootReducer from 'store/reducers'; // local root reducer

type Node = React.ReactElement<any>;

const themeInstance = shallow(<ThemeProvider theme={theme} />).instance() as any;
const StoreProvider = createProvider('store');
const createStore = configureStore();

const getStoreProvider = (initialState = {}) => {
  const mockStore = createStore(R.mergeDeepRight(rootReducer({} as any, {} as any), initialState));
  return new StoreProvider({ store: mockStore });
};
const getProvidersContexts = (storeProvider: any) => ({ store: storeProvider.getChildContext().store });

export const mountWithProviders = (initialState = {}) => {
  const storeProvider = getStoreProvider(initialState);
  return (node: Node) => {
    return mount(React.cloneElement(node, getProvidersContexts(storeProvider)), {
      context: { ...getProvidersContexts(storeProvider), ...themeInstance.getChildContext() },
      childContextTypes: {
        ...ReduxProvider.childContextTypes,
        ...ThemeProvider.childContextTypes,
      },
    });
  };
};

Then you can basically do this:

const wrapper = mountWithProviders()(<MyComponent />);

@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

(import * as React is categorically incorrect; if you're using TypeScript and it's forcing you to do that, it's broken and violates the spec, and you need the synthetic imports option)

Thanks, that clarifies things - that means it's definitely not cloning, it's potentially something grid-styled is doing.

@karolisgrinkevicius
Copy link
Author

Could you please clarify what this means?

it's broken and violates the spec

@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

Yes; Typescript has broken behavior for many versions where import * as was needed to bring in CJS modules, but the spec requires that import * as bring in a frozen Module namespace object. import React as 'react' is the only thing that is correct, ever.

@karolisgrinkevicius
Copy link
Author

I also took a try without cloning a node itself and passing it directly to mount but result is the same.

@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

Thanks, that clears up that it's not related to cloning.

Tag 14 is a ForwardRef - this will be resolved by #1592, and is a duplicate of #1604

@ljharb ljharb closed this as completed Jul 30, 2018
@ljharb ljharb moved this from Needs Triage to Refs in React 16 Jul 30, 2018
@mockey-jockey

This comment has been minimized.

@ljharb

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
React 16
  
Refs
Development

No branches or pull requests

4 participants