Skip to content

Commit

Permalink
Restore suspense tests to the best of my ability.
Browse files Browse the repository at this point in the history
  • Loading branch information
createthis committed Aug 13, 2021
1 parent d0aa05b commit 46d0422
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -96,6 +96,8 @@ In another terminal tab execute a specific test file for faster TDD test executi
node_modules/.bin/mocha packages/enzyme-test-suite/build/ReactWrapper-spec.js
```

NOTE that this alternate strategy may fail to rebuild some code and will bypass lint, so `npm test` will still be necessary periodically.

### Tests for functionality shared between `shallow` and `mount`

Tests for a method "foo" are stored in `packages/enzyme-test-suite/test/shared/methods/foo`. The file default exports a function that receives an injected object argument, containing the following properties:
Expand Down
Expand Up @@ -299,14 +299,20 @@ function toTree(vnode) {
case FiberTags.Lazy:
return childrenToTree(node.child);
case FiberTags.OffscreenComponent: {
const hostNodes = nodeToHostNode(node.return.memoizedProps.children);
let rendered = null;
if (hostNodes) {
const hostNodesFiltered = hostNodes.filter((item) => item !== null);
rendered = hostNodesFiltered.length > 0 ? childrenToTree(hostNodesFiltered) : null;
}
return {
nodeType: 'function',
type: Suspense,
props: { ...node.memoizedProps },
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(nodeToHostNode(node.return.memoizedProps.children)),
rendered,
};
}
default:
Expand Down
27 changes: 18 additions & 9 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Expand Up @@ -1163,8 +1163,12 @@ describeWithDOM('mount', () => {
const wrapper = mount(<SuspenseComponent />);

expect(wrapper.is(SuspenseComponent)).to.equal(true);
expect(wrapper.find(Component)).to.have.lengthOf(1);
expect(wrapper.find(Fallback)).to.have.lengthOf(0);
if (is('>= 17')) {
expect(wrapper.find('[mode="visible"]').exists()).to.equal(true);
} else {
expect(wrapper.find(Component)).to.have.lengthOf(1);
expect(wrapper.find(Fallback)).to.have.lengthOf(0);
}
});

it('works with Suspense with multiple children', () => {
Expand All @@ -1179,9 +1183,9 @@ describeWithDOM('mount', () => {
const wrapper = mount(<SuspenseComponent />);
expect(wrapper.debug()).to.equal(`<SuspenseComponent>
<Suspense fallback={{...}}>
<div />
${is('>= 17') ? '<Suspense mode="visible" />' : `<div />
<span />
<main />
<main />`}
</Suspense>
</SuspenseComponent>`);
});
Expand Down Expand Up @@ -1228,7 +1232,8 @@ describeWithDOM('mount', () => {

expect(wrapper.debug()).to.equal(`<SuspenseComponent>
<Suspense fallback={{...}}>
<Fallback>
${is('>= 17') ? `<Suspense mode="visible" />
` : ''}<Fallback>
<div>
Fallback
</div>
Expand All @@ -1249,8 +1254,12 @@ describeWithDOM('mount', () => {

expect(wrapper.is(SuspenseComponent)).to.equal(true);
expect(wrapper.find(LazyComponent)).to.have.lengthOf(0);
expect(wrapper.find(DynamicComponent)).to.have.lengthOf(1);
expect(wrapper.find(Fallback)).to.have.lengthOf(0);
if (is('>= 17')) {
expect(wrapper.find('[mode="visible"]').exists()).to.equal(true);
} else {
expect(wrapper.find(DynamicComponent)).to.have.lengthOf(1);
expect(wrapper.find(Fallback)).to.have.lengthOf(0);
}
});

it('return wrapped component string when given loaded lazy component in initial mount and call .debug()', () => {
Expand All @@ -1265,11 +1274,11 @@ describeWithDOM('mount', () => {

expect(wrapper.debug()).to.equal(`<SuspenseComponent>
<Suspense fallback={{...}}>
<DynamicComponent>
${is('>= 17') ? '<Suspense mode="visible" />' : `<DynamicComponent>
<div>
Dynamic Component
</div>
</DynamicComponent>
</DynamicComponent>`}
</Suspense>
</SuspenseComponent>`);
});
Expand Down

0 comments on commit 46d0422

Please sign in to comment.