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

Support of shallow for React16 Portals #1507

Closed
2 of 4 tasks
Tracked by #1553
danilvalov opened this issue Feb 2, 2018 · 2 comments
Closed
2 of 4 tasks
Tracked by #1553

Support of shallow for React16 Portals #1507

danilvalov opened this issue Feb 2, 2018 · 2 comments

Comments

@danilvalov
Copy link

danilvalov commented Feb 2, 2018

import React, {Component} from 'react';
import {createPortal} from 'react-dom';
import Enzyme, {mount, shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({
  adapter: new Adapter()
});

class Test extends Component {
  render () {
    return createPortal(
      <div>Test</div>,
      document.createElement('div')
    );
  }
}

describe('Test', () => {
  it('Should be rendered', () => {
    // Mount
    let TestComponentMount = mount(<Test />);
    console.log(TestComponentMount.debug());

    // Shallow
    let TestComponentShallow = shallow(<Test />);
    console.log(TestComponentShallow.debug());
  });
});

Current behavior

  console.log test.js:23      // Mount result
    <Test>
      <div>
        Test
      </div>
    </Test>

  console.log test.js:27      // Shallow result
    <undefined />

Expected behavior

I think Enzyme should use the shallow method correctly with Portals. Mount is not an universal method. If we have a component with not a simple child (eg, with some providers - intl, redux etc.), we can't mount the parent component. And we have to use the shallow method.

Your environment

Mac OS Sierra 10.13.3
Node Version 8.9.4
NPM Version 5.6.0
Yarn Version 1.3.2

API

  • shallow
  • mount
  • render

Version

library version
Enzyme 3.2.0
React 16.2.0

Adapter

  • enzyme-adapter-react-16
@koba04
Copy link
Contributor

koba04 commented Feb 24, 2018

I think it seems to be hard to support Portal in enzyme's shallow because React ShallowRenderer doesn't support Portal.
So I guess we should add Portal support into React ShallowRenderer in order to do this.

@ljharb ljharb mentioned this issue Mar 2, 2018
41 tasks
@ljharb
Copy link
Member

ljharb commented Aug 18, 2018

This should be handled by #1761 and #1760, which will be in the next semver-minor release.

@ljharb ljharb closed this as completed Aug 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants