diff --git a/src/ReactSeventeenAdapter.js b/src/ReactSeventeenAdapter.js index 4bddddd..cfe46ce 100644 --- a/src/ReactSeventeenAdapter.js +++ b/src/ReactSeventeenAdapter.js @@ -475,7 +475,7 @@ class ReactSeventeenAdapter extends EnzymeAdapter { rootNode, nodeHierarchy, nodeTypeFromType, - adapter.displayNameOfNode, + adapter.displayNameOfNode.bind(adapter), catchingType, ); }, @@ -708,7 +708,7 @@ class ReactSeventeenAdapter extends EnzymeAdapter { cachedNode, nodeHierarchy.concat(cachedNode), nodeTypeFromType, - adapter.displayNameOfNode, + adapter.displayNameOfNode.bind(adapter), cachedNode.type, ); }, diff --git a/test/test/shared/lifecycles/componentDidCatch.jsx b/test/test/shared/lifecycles/componentDidCatch.jsx index 5aa4b5c..0343e55 100644 --- a/test/test/shared/lifecycles/componentDidCatch.jsx +++ b/test/test/shared/lifecycles/componentDidCatch.jsx @@ -46,12 +46,13 @@ export default function describeCDC({ Wrap, isShallow }) { } render() { + const { ThrowerComponent } = this.props; const { didThrow, throws } = this.state; return (
- +
{didThrow ? 'HasThrown' : 'HasNotThrown'}
@@ -60,6 +61,10 @@ export default function describeCDC({ Wrap, isShallow }) { } } + ErrorBoundary.defaultProps = { + ThrowerComponent: Thrower, + }; + function ErrorSFC(props) { return ; } @@ -114,6 +119,37 @@ export default function describeCDC({ Wrap, isShallow }) { }); }); + it('catches a simulated error on memo() component', () => { + const MemoThrower = React.memo(Thrower); + const spy = sinon.spy(); + const wrapper = Wrap(); + + expect(spy).to.have.property('callCount', 0); + + expect(() => wrapper.find(Thrower).simulateError(errorToThrow)).not.to.throw(); + + expect(spy).to.have.property('callCount', 1); + + expect(spy.args).to.be.an('array').and.have.lengthOf(1); + const [[actualError, info]] = spy.args; + expect(() => { + throw actualError; + }).to.throw(errorToThrow); + expect(info).to.deep.equal({ + componentStack: ` + in Memo(Thrower) (created by ErrorBoundary) + in span (created by ErrorBoundary)${ + hasFragments + ? '' + : ` + in main (created by ErrorBoundary)` + } + in div (created by ErrorBoundary) + in ErrorBoundary (created by WrapperComponent) + in WrapperComponent`, + }); + }); + it('rerenders on a simulated error', () => { const wrapper = Wrap();