testing-library / react-testing-library

🐐 Simple and complete React DOM testing utilities that encourage good testing practices.
https://testing-library.com/react
MIT License
18.84k stars 1.1k forks source link

React-Aria Component Combobox is not Fully rendering in Consuming Application Tests #1339

Open adsaines opened 2 weeks ago

adsaines commented 2 weeks ago

Our Various Versions of Things

Relevant code or config:

it('should call to "MYAPI" when I enter values into my input', async () => {
        const user = userEvent.setup();
        const searchTerm = 'racc';
        const myContext = {...mockContext};
        renderContext(myContext)

        // click radio button for input to appear
        const showInputRadio = await screen.findAllByRole('radio', { name: 'Yes' });
        showInputRadio[0].click();
        // type our search in here
        // Here's the ISSUE spot: the input here is not being fully rendered / doesn't have all of the aria values & roles
        const input = screen.getByPlaceholderText('Type to Start Searching...');
        input.click();
        await user.type(input, searchTerm);

        await waitFor(() => {
            expect(fetchMock).toHaveBeenCalledWith(
                `/api/MYAPI?term=${searchTerm}`,
                buildRequestBody({}, 'GET')
            )
            expect(fetchMock).toHaveBeenCalledTimes(2);
        })
    })

What you did:

We built a component library for internal use at our company using React-Aria components. We ingest / consume the library in a separate application.

What happened / Problem Description:

Our components will render fully within the component library and can be tested to their full functionality: clicking, typing, searching, hit's api... etc. We confirmed that it works on our local & dev branches when running normally.

However, when we run our tests in the consuming application the input box that get's rendered in the testing dom is not fully filled out and the interactions do not properly execute. In this particular instance, we cannot type into the input to trigger the API call.

Example of Input rendered within our component tests...

Screenshot 2024-07-01 at 12 11 40 PM

Example of Input rendered within our consuming application using the same component...

Screenshot 2024-07-01 at 12 13 12 PM

Reproduction:

Unfortunately it is not possible in this situation to setup an example.

Suggested solution, sorry, we don't really have one

We have tried a mix of userEvent.type and fireEvent.change to alter the input's value. we have tried firing those events at different levels of the component. We have tried selecting using different methodologies (find, query, get) on different values (test-id, placeholder, role... etc).

Ultimately, we are confused and do not know why it is not rendering fully in the tests even though it works within the application itself. It's a definite turning point for us because if we can't test the components that we create outside of the library we're gonna have to scrap it and start over.

MatanBobi commented 1 week ago

Hi @adsaines I understand the situation but without a proper reproduction it will only be guessing and it looks like this has too many internal solutions to even try and guess what's happening there. Please try to create a minimal reproduction so we'll be able to try and assist here.