New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-get-element

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-get-element

To get the element in the path string from 'React Component'

latest
Source
npmnpm
Version
0.9.0
Version published
Maintainers
1
Created
Source

react-get-element

To get the HTML DOM Element in the path string from 'React Component'.

  • Like jquery|.get()
  • In easy-to-understand
  • It can be obtained in the path, such as the div.span.p and table:class1.tbody
  • Recommended be used in React Component of test(bdd)

Installation

npm install react-get-element --save

import getElement from 'react-get-element';

Usage

  • The path in the tag, id or class name
  • Symbols
    • Hierarchy with a .
    • # to id
    • : to class name

Tags specified

export default class Foo extends React.Component {
  render() {
    return (
      <div id="root">
        <div id="main">
          <div className="class1">
            <span>span-text</span>
          </div>
          <p className="class2">test</p>
          <p>p-text1</p>
          <p>p-text2</p>
        </div>
      </div>
    );
  }
}

const component = ReactTestUtils.renderIntoDocument(<Foo />);
const elements = ReactTestUtils.findAllInRenderedTree(component, c => c.id ? c.id === 'main' : false);

getElement(elements, "div#main.div:class1");
// => div element

getElement(elements, "div#main.p:class2");
// => p element

getElement(elements, "div#main.p:class2");
// => p element

getElement(elements, "div.span");
// => span element

getElement(elements, "svg");
// => undefined

Features

  • It returns an array when there is more than one
  • If there is something..

Development

  • Check in the npm run at the project root directory.
npm install
npm run build

npm run test
npm run lint

LICENSE

MIT

Keywords

react

FAQs

Package last updated on 05 Sep 2016

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