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

Simplify defining a testing-library query #32

Open
jo-sm opened this issue May 26, 2023 · 0 comments
Open

Simplify defining a testing-library query #32

jo-sm opened this issue May 26, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jo-sm
Copy link
Contributor

jo-sm commented May 26, 2023

At the moment, to define a query we create a multi method and then methods on that:

(defmulti get-by
  (fn [by _ & _] by))

(defmethod get-by :test-id [_ selector & [scoped]] (query :getByTestId selector scoped))
(defmethod get-by :text [_ selector & [scoped]] (query :getByText selector scoped))

This is a little cumbersome, so how can we simplify this while preserving the API?

For example, while we could in theory make a macro which is similar to how the new matcher macro works:

(defquery get-by-text "getByText")

it's not ideal because it changes the external API from (get-by :text ...) to (get-by-text ...), so whatever the solution is should keep the current API, while also allowing extensibility, so that users can define their own queries such as (get-by :i18n ...).


An additional consideration, which might not necessarily need to be implemented as part of this improvement, is that the way we implement get-by etc. is a little different than the vanilla testing-library implementation, such that (get-by :text "hello world") by default looks for "hello world" on screen, and can optionally take a container as the second argument:

(get-by :text "hello world" (within (get-by :text "parent")))

But some queries like getByRole take a large range of options, so should we allow for maybe passing in the container or options as the second argument and then if there are three assume the order is value options container?

(get-by :role "button" (within (get-by :text "parent")))
(get-by :role "button" #js {:busy: true} (within (get-by :text "parent")))
@jo-sm jo-sm added the enhancement New feature or request label May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant