function setup(jsx: React.ReactElement) {
return { user: userEvent.setup(), ...render(jsx) };
}
Call
userEvent.setup() inside each test, or in a setup() helper that the test calls, before renderingThe docs recommend calling setup() inside each test, often through a small helper that returns { user, ...render(jsx) }. The beforeEach option is tempting but wrong. The docs discourage rendering or using user-event in before or after hooks. The module-level option is wrong too, because one shared instance leaks state between tests.
Read more
- user-event intro (https://testing-library.com/docs/user-event/intro)testing-library.com