Repository navigation
Direct call vs .setup() support in future #1158
|
Hello! I'm working on an upgrade to v14. The async API has helped smooth out a lot of our test code. So thanks! During review I got asked a question about the long term stability of the direct API calls. The question mostly comes from this statement in the documentation.
Are we to understand that directly invoking the APIs will eventually be deprecated or removed? Or is the intent to provide continued support for that style? Perhaps someone could explain the preference to use Thanks! |
Replies: 1 comment 2 replies
|
Good afternoon. In my opinion, the main advantage of await user.keyboard('[ShiftLeft>]') In this case, the click retains the keyboard state from the previous interaction, just as it would during a real user interaction. With direct API calls, such as userEvent.click(), setup() is invoked internally for each call. This makes the direct API convenient for simple tests, but separate calls don't share the same input device state. Using setup() also makes it possible to configure an instance once and reuse it throughout a test, for example when testing clipboard interactions. Regarding deprecation, I would distinguish between the current recommendation and a confirmed future plan. The documentation explains that direct API calls are available to support migration from v13 and simple tests, but recommends using userEvent.setup() for new tests. I couldn't find an explicit statement that the direct APIs are scheduled for removal. It would be interesting to hear whether the maintainers intend to keep the direct APIs available in future major versions. |
Good afternoon. In my opinion, the main advantage of
userEvent.setup()is that it creates a reusable instance of a user event that shares the input device's state.For example:
const user = userEvent.setup()
await user.keyboard('[ShiftLeft>]')
await user.click(button)
In this case, the click retains the keyboard state from the previous interaction, just as it would during a real user interaction.
With direct API calls, such as userEvent.click(), setup() is invoked internally for each call. This makes the direct API convenient for simple tests, but separate calls don't share the same input device state.
Using setup() also makes it possible to configure an instance once and reuse it through…