Jest snapshot testing uses ReactTestRenderer but if my component contains a ref or uses ReactDOM.findDOMNode it throws TypeError: component.getPublicInstance is not a function.
Component
importReactfrom'react';exportdefaultclassLinkextendsReact.Component{render(){return(<aref={a=>this._a=a}href={this.props.page||'#'}>{this.props.children}</a>);}}Test
'use strict'importReactfrom'react';importLinkfrom'../Link';importrendererfrom'react-test-renderer';describe('Link',()=>{it('renders correctly',()=>{consttree=renderer.create(<Linkpage="foo"/>).toJSON();expect(tree).toMatchSnapshot();});});stack trace
FAIL __tests__/Link-test.js (2.148s)
● Link › it renders correctly
- TypeError: component.getPublicInstance is not a function
at attachRef (node_modules/react/lib/ReactRef.js:20:19)
at Object.ReactRef.attachRefs (node_modules/react/lib/ReactRef.js:42:5)
at attachRefs (node_modules/react/lib/ReactReconciler.js:26:12)
at CallbackQueue._assign.notifyAll (node_modules/react/lib/CallbackQueue.js:67:22)
at ReactTestReconcileTransaction.ON_DOM_READY_QUEUEING.close (node_modules/react/lib/ReactTestReconcileTransaction.js:37:26)
at ReactTestReconcileTransaction.Mixin.closeAll (node_modules/react/lib/Transaction.js:204:25)
at ReactTestReconcileTransaction.Mixin.perform (node_modules/react/lib/Transaction.js:151:16)
at batchedMountComponentIntoNode (node_modules/react/lib/ReactTestMount.js:61:27)
at ReactDefaultBatchingStrategyTransaction.Mixin.perform (node_modules/react/lib/Transaction.js:138:20)
at Object.ReactDefaultBatchingStrategy.batchedUpdates (node_modules/react/lib/ReactDefaultBatchingStrategy.js:63:19)
Jest snapshot testing uses ReactTestRenderer but if my component contains a ref or uses
ReactDOM.findDOMNodeit throwsTypeError: component.getPublicInstance is not a function.Component
Test
stack trace