npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-testid-generator

v1.0.3

Published

React Test Id Generator is a package that can auto generate test attributes for testing tools used by QA automatically. The attribute name required can be passed into a function and the package handles everything else.

Downloads

999

Readme

React Test Id Generator

React Test Id Generator is a package that can auto generate test attributes for testing tools used by QA automatically. The attribute name required can be passed into a function and the package handles everything else.

Usage

  • Install with
npm i react-testid-generator --save
  • import tagAttribute on a top level component like App.js or index.js as shown
import tagAttributes from 'react-testid-generator';
  • Call tagAttributes function in useEffect or componentDidUpdate as shown
useEffect(()=>{
  tagAttributes('data-test-id','',2000,[]);
})

In the above code the first parameter is the attribute name to be added to the html element, second parameter is the prefix if needed for the attribute value (can be left blank if not needed) passign 'pre-' for example would generate attributes like data-test-id = "pre-7a61787824", the third parameter is the delay before executing the function in milliseconds (if your application takes longer to load all the elements on the screen pass a higher delay), the fourth paramter is an array of text that can be passed in case there are custom html elements in the application like for the input would be ['hashif','dev'] (pass an empty array [] in case there are no custom elements)

  • Full code is shown below
import logo from './logo.svg';
import './App.css';
import { useState, useEffect } from 'react';
import tagAttributes from 'react-testid-generator';

function App() {

useEffect(()=>{
  tagAttributes('data-test-id','',2000,[]);
})

  return (
    <div className="App">
       .
       .
       .
    </div>
  );
}

export default App;

Note

This package can be used with JS frameworks like Angular or in any JS application. Please remember to call the function from an appropriate lifecycle hook equivalent depeneding on the stack.

Contact

In case of any doubts please contact me via mail [email protected] or via LinkedIn www.linkedin.com/in/hashif-habeeb-a82064162

Thanks

In case you are feeling down today here is an inspiring quote -

“Do what you can, with what you have, where you are.” ―Theodore Roosevelt.