Code Monkey home page Code Monkey logo

rtl-simple-queries's Introduction

rtl-simple-queries

Simple wrapper queries for @testing-library/react


Build Status Code Coverage version downloads MIT License

All Contributors

PRs Welcome Code of Conduct

The problem

To get an element from while testing with - @testing-library/react, we have 6 variants viz. getBy, getAllBy, queryBy, queryAllBy, findBy, and findAllBy.

We have to remember which one to use when. The name of methods is entirely a familiarity thing. But just by the name of the method it bit difficult to know which one would throw error if an element is not found or which takes into account async updates.

This solution

This library wraps those methods with easier to remember APIs

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev rtl-simple-queries

Usage

screen can be exported from 'rtl-simple-queries'

Addional parameters from sync query allowEmpty and allowMultiple and for async we only have one option allowMultiple

import {screen} from 'rtl-simple-queries'

fetchByText(/text/, {allowEmpty: true, allowMultiple: false})
fetchByText(/text/, {allowMultiple: false})
fetchByText(/text/)

// async
await fetchByTextAsync(/text/, {allowMultiple: true})

To use queies for scoped container we could do

// test-utils. js
function render(component, options) {
  const utils = rtlRender(component, options)
  const queries = getSimpleQueries(utils)
  return {...utils, ...renderSyncQueries}
}

// use this render instead of importing from @testing-library/react
const {fetchByText} = render(<p>text</p>)

Other Solutions

You can refer to cheatsheet as a quick reference.

Issues

Looking to contribute? Look for the Good First Issue label.

๐Ÿ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

๐Ÿ’ก Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a ๐Ÿ‘. This helps maintainers prioritize what to work on.

See Feature Requests

Contributors โœจ

Thanks goes to these people (emoji key):

Balavishnu V J
Balavishnu V J

๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ โš ๏ธ

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

rtl-simple-queries's People

Contributors

balavishnuvj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.