You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey Team, I'm having trouble running some of the simplest tests available in your repo. I keep receiving the following error after running the useState hook example:
1) #useContainer passes a function called callApi to the base component:
TypeError: Cannot read property 'appendChild' of undefined
at render (node_modules/react-testing-library/dist/index.js:58:31)
at renderHook (node_modules/react-hooks-testing-library/lib/index.js:71:49)
at Context.<anonymous> (app/bundles/tests/common/hooks/useContainer.test.js:37:24)
I'm haven't been able to deduce why this is occurring - does the library require a specific configuration with Babel potentially?
Here is my code:
import{useState}from'react';import{renderHook,cleanup,act}from'react-hooks-testing-library';import{describe,it,beforeEach,expect,}from'mocha';describe('useState',()=>{afterEach(cleanup);it('passes a function called callApi to the base component',()=>{const{ result }=renderHook(()=>useState('foo'));const[value]=result.current;expect(value).toBe('foo');});});
The text was updated successfully, but these errors were encountered:
It looks like you are having and issue with the underlying react-testing-library calls (which you may or may not have even known we use undder the hood). I'm guessing it's this line given the error and it's the only call to appendChild they make.
if you add console.log(document.body)at the start of your test, does it return anything? What about just document?
Most users I've seen so far are using jest as their test runner which sets up jsdom automatically, do you have a test dom set up somehow?
You were correct regarding Jsdom - by adding the library I was successful able to get around this issue. Our team has actually considered transferring out tests from Mocha to Jest, so I moved one of our libraries over and the react-hooks library has been working perfectly since.
What is your question:
Hey Team, I'm having trouble running some of the simplest tests available in your repo. I keep receiving the following error after running the useState hook example:
I'm haven't been able to deduce why this is occurring - does the library require a specific configuration with Babel potentially?
Here is my code:
The text was updated successfully, but these errors were encountered: