Skip to content

AppendChild error occurring on all calls of RenderHook #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sdzharkov opened this issue Mar 19, 2019 · 2 comments
Closed

AppendChild error occurring on all calls of RenderHook #17

sdzharkov opened this issue Mar 19, 2019 · 2 comments
Labels
question Further information is requested

Comments

@sdzharkov
Copy link

sdzharkov commented Mar 19, 2019

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:

  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');
  });
});
@sdzharkov sdzharkov added the question Further information is requested label Mar 19, 2019
@sdzharkov sdzharkov changed the title Support with Mocha AppendChild error occurring on all calls of RenderHook Mar 19, 2019
@mpeyper
Copy link
Member

mpeyper commented Mar 21, 2019

Hi @sdzharkov,

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?

@sdzharkov
Copy link
Author

Hey @mpeyper,

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.

Thanks for your help!

@mpeyper mpeyper mentioned this issue Mar 21, 2019
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants