You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove prefer-expect-query-by rule from shareable configs (#60)
* fix(prefer-expect-query-by): remove rule from recommended preset
* docs(prefer-expect-query-by): improve use cases and motivation
* docs(prefer-expect-query-by): get examples without negation back
# Disallow the use of `expect(getBy*)` (prefer-expect-query-by)
2
2
3
-
The (DOM) Testing Library allows to query DOM elements using different types of queries such as `getBy*` and `queryBy*`. Using `getBy*` throws an error in case the element is not found. This is useful when using method like `waitForElement`, which are `async` functions that will wait for the element to be found until a certain timeout, after that the test will fail.
4
-
However, when trying to assert if an element is not in the document, we can't use `getBy*` as the test will fail immediately. Instead it is recommended to use `queryBy*`, which does not throw and therefore we can assert that e.g. `expect(queryByText("Foo")).not.toBeInTheDocument()`.
3
+
The (DOM) Testing Library allows to query DOM elements using different types of queries such as `getBy*` and `queryBy*`. Using `getBy*` throws an error in case the element is not found. This is useful when:
5
4
6
-
> The same applies for the `getAll*` and `queryAll*` queries.
5
+
- using method like `waitForElement`, which are `async` functions that will wait for the element to be found until a certain timeout, after that the test will fail.
6
+
- using `getBy` queries as an assert itself, so if the element is not found the error thrown will work as the check itself within the test.
7
+
8
+
However, when trying to assert if an element is not present or disappearance, we can't use `getBy*` as the test will fail immediately. Instead it is recommended to use `queryBy*`, which does not throw and therefore we can assert that e.g. `expect(queryByText("Foo")).not.toBeInTheDocument()`.
9
+
10
+
> The same applies for the `getAll*` and `queryAll*` queries too.
7
11
8
12
## Rule details
9
13
10
14
This rule gives a notification whenever `expect` is used with one of the query functions that throw an error if the element is not found.
0 commit comments