reactjsjestjsreact-loadablereact-testing-library

Jest + React Loadable error Not supported


I'm trying to test a component that renders a couple of asynchronously imported children with React Loadable like a Modal for example. My test looks like this

// Using React Testing Library
import { fireEvent, getByTestId, wait } from 'react-testing-library';

test('with RTL', async () => {
    // There is a portal. I leave it in the code sample in case it gives any hints
    const portalNode = document.getElementById('overlay');
    const { container, getByLabelText } = render(<SearchFormComposed {...props} />);

    expect(portalNode.children.length).toBe(0);

    fireEvent.click(getByLabelText('MyButton'));

    const list = await wait(() => getByTestId(portalNode, 'myList'));

    console.log(list);
    expect(portalNode.children.length).toBe(1);

  });

The test gives a not very helpful error shown bellow

enter image description here

I can find no information about this error at all. Anyone could shed some light here please?

Thanks in advance for your time!


Solution

  • I had the same issue when i used 'plugin-syntax-dynamic-import' for dynamic import. switch it to 'babel-plugin-dynamic-import-node' helped me to resolve that.

    bablerc.js

    plugins: [
    // 'syntax-dynamic-import',
    'dynamic-import-node',
    ]