Socket
Socket
Sign inDemoInstall

@testing-library/cypress

Package Overview
Dependencies
201
Maintainers
11
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @testing-library/cypress

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


Version published
Weekly downloads
993K
decreased by-5.22%
Maintainers
11
Created
Weekly downloads
 

Readme

Source

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 in @types/testing-library__cypress at DefinitelyTyped, and should be added as follows in tsconfig.json:

{
  "compilerOptions": {
    "types": ["cypress", "@types/testing-library__cypress"]
  }
}

Usage

Cypress Testing Library extends Cypress' cy command.

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

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

You can find all Library definitions here.

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

💻
Brian Ng
Brian Ng

💻
Kari Laari
Kari Laari

📖
Basti Buck
Basti Buck

💻
ShimiTheFirst
ShimiTheFirst

🐛
omerose
omerose

📖
Aaron Mc Adam
Aaron Mc Adam

💻 ⚠️
Karl Horky
Karl Horky

📖
Stefano Magni
Stefano Magni

💻 ⚠️ 📖
Weyert de Boer
Weyert de Boer

💻
Simon Jespersen
Simon Jespersen

💻 👀
Adrià Fontcuberta
Adrià Fontcuberta

🚇 📖
Mikhail Guskov
Mikhail Guskov

🐛

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

LICENSE

MIT

Keywords

FAQs

Last updated on 04 Sep 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc