Skip to content

Commit

Permalink
[Tests] work around React < 15 mount errors with certain HTML tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 27, 2019
1 parent ef6c8b3 commit 018ff33
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"eslint-plugin-react": "^7.12.4",
"react-is": "^16.7.0"
}
}
}
29 changes: 26 additions & 3 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,28 @@ describeWithDOM('mount', () => {
});
});

// in React 0.13 and 0.14, these HTML tags get moved around by the DOM, and React fails
// they're tested in `shallow`, and in React 15+, so we can skip them here.
const tagsWithRenderError = new Set([
'body',
'frame',
'frameset',
'head',
'html',
'caption',
'td',
'th',
'tr',
'col',
'colgroup',
'tbody',
'thead',
'tfoot',
]);
function hasRenderError(Tag) {
return is('< 15') && tagsWithRenderError.has(Tag);
}

describeWithDOM('find DOM elements by constructor', () => {
const { elements, all } = getData();

Expand All @@ -1541,11 +1563,12 @@ describeWithDOM('mount', () => {
}
}

it(`${Tag}: finds by constructor “${name}`, () => {
itIf(!hasRenderError(Tag), `${Tag}: found with \`${name}\``, () => {
const wrapper = mount(<Foo />);

expect(wrapper.childAt(0).type()).to.equal(Tag);
expect(wrapper.childAt(0).is(Tag)).to.equal(true);
const rendered = wrapper.childAt(0);
expect(rendered.type()).to.equal(Tag);
expect(rendered.is(Tag)).to.equal(true);
expect(wrapper.find(Tag)).to.have.lengthOf(1);
});
});
Expand Down
7 changes: 4 additions & 3 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,12 @@ describe('shallow', () => {
}
}

it(`${Tag}: finds by constructor “${name}`, () => {
it(`${Tag}: found with \`${name}\``, () => {
const wrapper = shallow(<Foo />);

expect(wrapper.type()).to.equal(Tag);
expect(wrapper.is(Tag)).to.equal(true);
const rendered = wrapper;
expect(rendered.type()).to.equal(Tag);
expect(rendered.is(Tag)).to.equal(true);
expect(wrapper.filter(Tag)).to.have.lengthOf(1);
});
});
Expand Down

0 comments on commit 018ff33

Please sign in to comment.