Skip to content

consider using userEvent rather than fireEvent #394

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
markgoho opened this issue Jun 14, 2023 · 5 comments · Fixed by #395
Closed

consider using userEvent rather than fireEvent #394

markgoho opened this issue Jun 14, 2023 · 5 comments · Fixed by #395

Comments

@markgoho
Copy link
Contributor

markgoho commented Jun 14, 2023

according to the docs

Most projects have a few use cases for fireEvent, but the majority of the time you should probably use @testing-library/user-event

Here's an updated version of 00-single-component.spec.ts:

import { render, screen } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';

import { SingleComponent } from './00-single-component';

test('renders the current value and can increment and decrement', async () => {
  const user = userEvent.setup()
  await render(SingleComponent);

  const incrementControl = screen.getByRole('button', { name: /increment/i });
  const decrementControl = screen.getByRole('button', { name: /decrement/i });
  const valueControl = screen.getByTestId('value');

  expect(valueControl).toHaveTextContent('0');

  await user.click(incrementControl);
  await user.click(incrementControl);
  expect(valueControl).toHaveTextContent('2');

  await user.click(decrementControl);
  expect(valueControl).toHaveTextContent('1');
});
@sysmat
Copy link

sysmat commented Jun 15, 2023

  • userEvent in my case on Chrome Headless 90. not working

@markgoho
Copy link
Contributor Author

  • userEvent in my case on Chrome Headless 90. not working

have you considered updating to the latest version? v112 was released in March

@sysmat
Copy link

sysmat commented Jun 16, 2023

  • we have CI with different chrome versions and fireEvent work for all of them, but userEvent is not

@timdeschryver
Copy link
Member

Yea, using userEvent is recommended and it would be better to update the examples to use it 😅
Preferably we should also update to the latest user-event version.

Do you want to create a PR for this @markgoho ?

@markgoho
Copy link
Contributor Author

Yea, using userEvent is recommended and it would be better to update the examples to use it 😅 Preferably we should also update to the latest user-event version.

Do you want to create a PR for this @markgoho ?

Yes, would love to do this!

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

Successfully merging a pull request may close this issue.

3 participants