Jest tests fails on Link components using spy and containerId
Hi, I'm having a really weird issue with the Link component and jest tests; if I use the props spy=true and containerId the related test fails with the error TypeError: Cannot read property 'spyCallbacks' of undefined
This is the stack trace:
at Object.addSpyHandler (node_modules/react-scroll/modules/mixins/scroll-spy.js:59:20)
at Link.componentDidMount (node_modules/react-scroll/modules/mixins/scroll-link.js:119:31)
at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:14685:22)
at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15905:7)
at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:145:14)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:195:16)
at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:248:31)
at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:16075:7)
at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:17463:3)
at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:17391:9)
at performWork (node_modules/react-dom/cjs/react-dom.development.js:17295:7)
at performSyncWork (node_modules/react-dom/cjs/react-dom.development.js:17267:3)
at requestWork (node_modules/react-dom/cjs/react-dom.development.js:17155:5)
at scheduleWork (node_modules/react-dom/cjs/react-dom.development.js:16949:5)
at scheduleRootUpdate (node_modules/react-dom/cjs/react-dom.development.js:17637:3)
at updateContainerAtExpirationTime (node_modules/react-dom/cjs/react-dom.development.js:17664:10)
at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:17691:10)
at ReactRoot.Object.<anonymous>.ReactRoot.render (node_modules/react-dom/cjs/react-dom.development.js:17957:3)
at node_modules/react-dom/cjs/react-dom.development.js:18097:14
at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:17518:10)
at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:18093:5)
at Object.render (node_modules/react-dom/cjs/react-dom.development.js:18152:12)
at Object.render (src/App.test.js:11:12)
Bear in mind that the component behave correctly in running time, but the test fails. If I don't use spy and containerId at the same time, the unit test pass as it should be. I'm really clueless about this error and how to solve it. Thanks for your help. Jose.
Environment:
"react": "^16.4.2",
"jest": "23.6.0",
"react-dom": "^16.4.2",
"react-scroll": "^1.7.10",
I was having the same problem (but I'm using Enzyme). When I mount my component, i also use the mount option attachTo (docs)
so my mount looks like:
mount(
<MyComponent />
, { attachTo: document.body }
)
Hope that helps!
Hi @davywentworth
Adding attachTo: DOM element did not help
Wrapper the component like
<div id="containerId">
<MyComponent />
</div>