Skip to content
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

Issues with fireEvent or userEvent Not Working in Unit Tests for Components Using useComboBox from react-aria #1628

Open
ryanpark opened this issue Oct 18, 2024 · 0 comments

Comments

@ryanpark
Copy link

ryanpark commented Oct 18, 2024

Hi

I am trying to write unit tests for a component built using useComboBox, but it seems that fireEvent or userEvent is not triggering the input changes as expected. Specifically, I want to verify that when I type in the input field, the suggestions are displayed correctly.

my test :

it.only('should allow typing in the input and show suggestions', async () => {
    render(<AutoComplete items={mockItems} />);
    const inputElement = screen.getByRole('textbox');
    
    console.log(prettyDOM(inputElement));
    
    inputElement.focus();

   
    fireEvent.change(inputElement, { target: { value: 'liv' } }); // or
    userEvent.type(inputElement, 'liv', { delay: 100 });
    
    await waitFor(() => {
      const popover = screen.getByTestId('popover');
      expect(popover.length).toBeGreaterThan(0);
    });
    
    screen.debug();
  });

Obviously, it works as expected at the browser level functionally, but not in the unit tests. Is there something I might be missing in my setup, or is there a specific way I should be using fireEvent or userEvent with components that use useComboBox from react-aria ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant