-
Notifications
You must be signed in to change notification settings - Fork 272
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
feat: add query API #13
Conversation
README.md
Outdated
@@ -282,6 +282,30 @@ test('fetch data', async () => { | |||
}); | |||
``` | |||
|
|||
## `query` APIs | |||
|
|||
Each of the get APIs listed in the render section above have a complimentary query API. The get APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the DOM, then you can use the query API instead: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are not using DOM here C:
src/render.js
Outdated
@@ -30,6 +39,15 @@ export default function render( | |||
getAllByName: getAllByName(instance), | |||
getAllByText: getAllByText(instance), | |||
getAllByProps: getAllByProps(instance), | |||
|
|||
queryByTestId: queryByTestId(instance), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should replace exports from getBy API
and queryBy API
by some factory function to avoid listing all the re-exports here. Eg.
// getBy.js
...
export const getByAPI (instance) => ({
queryByTestId: queryByTestId(instance),
...
});
// render.js
return {
...getByAPI(instance),
...queryByAPI(instance),
...
}
Summary
query
APIs corresponding toget
APIs. For simplicity and code reuse I've decided to go with callingget
APIs directly – as a downside we throw/catch errors twice. If this ever has a bigger perf impact we can switch the implementation.Fixes #6
Test plan
Added unit tests