Git Product home page Git Product logo

cypress-testing-library's Introduction

cypress-testing-library

tiger

Simple and complete custom Cypress commands and utilities that encourage good testing practices.

Read the docs | Edit the docs


Build Status Code Coverage version downloads MIT License

All Contributors PRs Welcome Code of Conduct

Watch on GitHub Star on GitHub Tweet

The problem

You want to use dom-testing-library methods in your Cypress tests.

This solution

This allows you to use all the useful dom-testing-library methods in your tests.

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 @testing-library/cypress

With typescript

Typings are defined under @testing-library/cypress/typings, and should be added as follows in tsconfig.json:

{
  "compilerOptions": {
    "types": ["cypress", "../@testing-library/cypress/typings"]
  }
}

Usage

cypress-testing-library extends Cypress' cy command.

Add this line to your project's cypress/support/commands.js:

import 'cypress-testing-library/add-commands';

You can now use all of dom-testing-library's getBy, getAllBy, queryBy and queryAllBy commands. See the dom-testing-library docs for reference

To show some simple examples (from cypress/integration/commands.spec.js):

cy.getAllByText('Jackie Chan').click()
cy.queryByText('Button Text').should('exist')
cy.queryByText('Non-existing Button Text').should('not.exist')
cy.queryByLabelText('Label text', {timeout: 7000}).should('exist')
cy.get('form').within(() => {
  cy.getByText('Button Text').should('exist')
})
cy.get('form').then(subject => {
  cy.getByText('Button Text', {container: subject}).should('exist')
})

cypress-testing-library supports both jQuery elements and DOM nodes. This is necessary because Cypress uses jQuery elements, while dom-testing-library expects DOM nodes. When you pass a jQuery element as container, it will get the first DOM node from the collection and use that as the container parameter for the dom-testing-library functions.

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors

Thanks goes to these people (emoji key):

Kent C. Dodds
Kent C. Dodds

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

๐Ÿ’ป ๐Ÿค”
ลukasz Gandecki
ลukasz Gandecki

๐Ÿ’ป โš ๏ธ
Peter Kamps
Peter Kamps

๐Ÿ’ป ๐Ÿ“– ๐Ÿค” โš ๏ธ
Airat Aminev
Airat Aminev

๐Ÿ’ป โš ๏ธ ๐Ÿ”ง
Adrian Smijulj
Adrian Smijulj

๐Ÿ’ป
Soo Jae Hwang
Soo Jae Hwang

๐Ÿ› ๐Ÿ’ป โš ๏ธ
Justin Hall
Justin Hall

๐Ÿ’ป โš ๏ธ
euzebe
euzebe

๐Ÿ“–
jkdowdle
jkdowdle

๐Ÿ’ป

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

LICENSE

MIT

cypress-testing-library's People

Contributors

aaronmcadam avatar adrians5j avatar airato avatar alexkrolick avatar euzebe avatar gnapse avatar jkdowdle avatar lgandecki avatar misoguy avatar npeterkamps avatar rakannimer avatar sompylasar avatar wkovacs64 avatar zaktax avatar

Watchers

 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.