Skip to content

Commit

Permalink
[enzyme-adapter-react-16] Don’t show wrapped component displayName in…
Browse files Browse the repository at this point in the history
… lazy component
  • Loading branch information
chenesan authored and ljharb committed Mar 19, 2019
1 parent 3d69f00 commit b5afdb9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 55 deletions.
6 changes: 1 addition & 5 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Expand Up @@ -754,11 +754,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
return name ? `ForwardRef(${name})` : 'ForwardRef';
}
case Lazy || NaN: {
if (type.displayName) {
return type.displayName;
}
const name = displayNameOfNode({ type: type._result });
return name ? `lazy(${name})` : 'lazy';
return 'lazy';
}
default: return displayNameOfNode(node);
}
Expand Down
36 changes: 0 additions & 36 deletions packages/enzyme-test-suite/test/Adapter-spec.jsx
Expand Up @@ -1079,42 +1079,6 @@ describe('Adapter', () => {
const LazyComponent = lazy(() => fakeDynamicImport(DynamicComponent));
expect(getDisplayName(<LazyComponent />)).to.equal('lazy');
});

itIf(is('>= 16.6'), 'show explicitly defined display name of lazy component', () => {
class DynamicComponent extends React.Component {
render() {
return <div>DynamicComponent</div>;
}
}
const theDisplayName = 'SOMETHING';
const LazyComponent = Object.assign(lazy(() => fakeDynamicImport(DynamicComponent)), { displayName: theDisplayName });
expect(getDisplayName(<LazyComponent />)).to.equal(theDisplayName);
});

itIf(is('>= 16.6'), 'show display name of wrapped component of lazy', () => {
class ComponentWithDisplayName extends React.Component {
render() {
return <div>DynamicComponent</div>;
}
}
ComponentWithDisplayName.displayName = 'Something';
const LazyComponent = lazy(() => fakeDynamicImport(ComponentWithDisplayName));
/* eslint-disable no-underscore-dangle */
LazyComponent._result = ComponentWithDisplayName;
expect(getDisplayName(<LazyComponent />)).to.equal(`lazy(${ComponentWithDisplayName.displayName})`);
});

itIf(is('>= 16.6'), 'show name of wrapped component of lazy if its displayName is empty', () => {
class ComponentWithoutDisplayName extends React.Component {
render() {
return <div>DynamicComponent</div>;
}
}
const LazyComponent = lazy(() => fakeDynamicImport(ComponentWithoutDisplayName));
/* eslint-disable no-underscore-dangle */
LazyComponent._result = ComponentWithoutDisplayName;
expect(getDisplayName(<LazyComponent />)).to.equal('lazy(ComponentWithoutDisplayName)');
});
});

describeIf(is('>= 16.2'), 'determines if node isFragment', () => {
Expand Down
14 changes: 0 additions & 14 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Expand Up @@ -1688,20 +1688,6 @@ describe('shallow', () => {
expect(wrapper.debug()).to.equal('<lazy />');
});

it('returns lazy component string including wrapped component when debug() is called and lazy component is loaded', () => {
const LazyComponent = lazy(fakeDynamicImport(DynamicComponent));
/* eslint-disable no-underscore-dangle */
LazyComponent._result = DynamicComponent;

const wrapper = shallow((
<Suspense fallback={<Fallback />}>
<LazyComponent />
</Suspense>
));

expect(wrapper.debug()).to.equal('<lazy(DynamicComponent) />');
});

it('replaces LazyComponent with Fallback when render Suspense if options.suspenseFallback=true', () => {
const LazyComponent = lazy(fakeDynamicImport(DynamicComponent));

Expand Down

0 comments on commit b5afdb9

Please sign in to comment.