- Notifications
You must be signed in to change notification settings - Fork2
Simple wrapper queries for @testing-library/react
License
balavishnuvj/rtl-simple-queries
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
To get an element from while testing with -@testing-library/react,we have 6 variants viz.getBy,getAllBy,queryBy,queryAllBy,findBy,andfindAllBy.
We have to remember which one to use when. The name of methods is entirely afamiliarity thing. But just by the name of the method it bit difficult to knowwhich one would throw error if an element is not found or which takes into account async updates.
This library wraps those methods with easier to remember APIs
This module is distributed vianpm which is bundled withnode andshould be installed as one of your project'sdevDependencies:
npm install --save-dev rtl-simple-queriesscreen can be exported from'rtl-simple-queries'
Addional parameters from sync queryallowEmpty andallowMultiple and forasync we only have one optionallowMultiple
import{screen}from'rtl-simple-queries'screen.fetchByText(/text/,{allowEmpty:true,allowMultiple:false})screen.fetchByText(/text/,{allowMultiple:false})screen.fetchByText(/text/)// asyncawaitscreen.fetchByTextAsync(/text/,{allowMultiple:true})
To use queies for scoped container we could do
// test-utils. jsfunctionrender(component,options){constutils=rtlRender(component,options)constqueries=getSimpleQueries(utils)return{...utils, ...renderSyncQueries}}// use this render instead of importing from@testing-library/reactconst{fetchByText}=render(<p>text</p>)
You can refer tocheatsheetas a quick reference.
Looking to contribute? Look for theGood First Issuelabel.
Please file an issue for bugs, missing documentation, or unexpected behavior.
Please file an issue to suggest new features. Vote on feature requests by addinga 👍. This helps maintainers prioritize what to work on.
Thanks goes to these people (emoji key):
Balavishnu V J 💻📖🚇 | Kent C. Dodds 🤔📖 | Paul Coroneos 📖 | Adam Ochayon 📖 |
This project follows theall-contributors specification.Contributions of any kind welcome!
MIT
About
Simple wrapper queries for @testing-library/react
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors4
Uh oh!
There was an error while loading.Please reload this page.