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

Add section for Testing User Actions #199

Closed
wants to merge 7 commits into from

Conversation

dominiclisjak
Copy link
Contributor

Help from ChatGPT :)


Here's a simple example using Jest and React Testing Library to test a button click:

```jsx
Copy link

@darrac darrac Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cover some more tricky examples. For example, try out the 'should render toggle show more/less button' (yes, the name is weird) test in CountryFilterGroup.test.tsx in the Messe repository.

`
it.only("should render toggle show more/less button", async () => {
let showLessButton = screen.queryByRole("button", { name: /showless/i });

		expect(showLessButton).toBeNull();

		let showMoreButton = screen.queryByRole("button", { name: /showmore/i });

		await userEvent.click(showMoreButton as HTMLButtonElement);

		showMoreButton = screen.queryByRole('button', { name: /showmore/i });
		expect(showMoreButton).toBeNull();
		showLessButton = screen.queryByRole('button', { name: /showless/i });
		expect(showLessButton).toBeInstanceOf(HTMLButtonElement);
	});

`

  1. It must await the user action to succeed. Why, because of something specific in that component?
  2. Some other tests use fireEvent which we should probably avoid in favour of userEvent?
  3. Our existing chapter suggests we use waitFor but the test I linked doesn't use it. When do we need to use waitFor if ever?

Also how does this fit in in the existing chapter. Maybe I should have told you upfront that the chapter already exist, and maybe you should have known :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated test cases.

  1. Added a chapter explaining usage of await,
  2. Definitely.
  3. Updated the Existing chapter.

@kamdubiel
Copy link
Contributor

Done in:
#203

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