Skip to content

Shallow does not find direct child when inside React.Fragment #1664

@sepo27

Description

@sepo27

Describe the bug
Shallow should find direct child when inside React.Fragment.
(At least it does so for indirect descendants).

To Reproduce

import * as React from 'react';
import {shallow} from 'enzyme';

const MyCom = () => (
  <div className="container">
    <React.Fragment>
      <span>A span</span>
    </React.Fragment>
  </div>
);

describe('enzyme shallow', () => {
  it('test#1: should find descendant span inside fragment ', () => {
    const myCom = shallow(<MyCom />);
    expect(myCom.find('.container span')).toHaveLength(1);
  });

  // TEST FAILS
  it('test#2: should find direct child span inside fragment', () => {
    const myCom = shallow(<MyCom />);
    expect(myCom.find('.container > span')).toHaveLength(1);
  });
});

Expected behavior
Expect test#2 to pass.

Desktop (please complete the following information):

  • OS: Ubuntu 16.04 LTS GNOME
  • Browser: X
  • Version: X

Additional context
Tests are failing inside Jest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions