Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@lukaspolak/react-get-data-cy

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lukaspolak/react-get-data-cy

Helper function provides a `data-cy` testing attribute with a value that can match the text content of the react element.

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

react-get-data-cy

checks-status workflow/status codecov npm bundle size npm

Helper function provides a data-cy testing attribute with a value that can match the text content of the react element.

Demo

CodeSandbox

Motivation

I wanted to have a dynamic data-cy testing attribute that can be based on children passed to react element. This package supports string, JSX.Element and ReactNode as value i.e. second argument.

Getting started

To use this package, you only need to install this dependency, import it and invoke the getDataCy function, e.g.:

import { getDataCy } from '@lukaspolak/react-getDataCy'

export const FancyComponent: FC = ({ children }) => {
  return <div {...getDataCy('fancy component', children)}>{children}</div>
}

Install

npm install @lukaspolak/react-get-data-cy

or

yarn add @lukaspolak/react-get-data-cy

Documentation

This package works well with babel-plugin-react-remove-properties. To configure it, update .babelrc file.

{
  //...
  "env": {
    "production": {
      "plugins": [["react-remove-properties", { "properties": ["data-cy"] }]]
    }
  }
  //...
}

Contributing

Please read the Contribution guidelines to start with your awesome contributions!

Why the library is prefixed with @lukaspolak/

There are a lot of similar libraries/packages on GitHub and npm, that can do the same. I wanted to enhance my programming skills, and I didn't want to find a unique name for the package.

INITIALIZATION TODO

  • remove INITIALIZATION TODO section
  • replace quoted text in README.md file

Keywords

cypress

FAQs

Package last updated on 13 Feb 2021

Did you know?

Socket

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