How to render two components while testing using react-testing library?

Viewed 1701

i want to render two components using react testing library.

i have two components namely firstComponent and secondComponent

within my tests i render one compoennt like below

test('check test', async() => {
    const { getByTestId } = utils.render(
        <firstComp />,
        [
            utils.gqlMock(queryname, query-type),
        ]
    );
    //some logic here to do with getBytestid
)};

Now the question is how can i render component secondComponent with mock within utils.render method

i tried something like

test('check test', async() => {
    const { getByTestId } = utils.render(
        <secondComp/>,
        [  utils.gqlMock(queryname3, query-type3),
        ]
        <firstComp />,
        [
            utils.gqlMock(queryname, query-type),
        ]
    );
    //some logic here to do with getBytestid
)};

But this throws some errors. doesnt seem to be the right way. could someone help me with this. thanks.

1 Answers

I never did this but I would try something like this :

    const { getByTestId } = utils.render(
        <>
           <SecondComponent />
           <FirstComponent />
        </>,
        [...]
    );
Related