Matchers Object

Functions for locating particular a DOM node or component from the list of matches found by Scope#find.

Static Methods

    at(desiredIndex: Number) -> Matcher

    Select a component or a DOM node at a specified index from the list of matches.

    // find the fourth Button under component
    drill(component).find(Button, m.at(3))

    hasAttribute(name: String, value: *) -> Matcher

    Create a matcher function that tests a DOM node for either having a certain attribute at all, or for having that attribute with a specific value.

    Parameters (2)

    name
    String

    The attribute name.

    value
    *

    The attribute value. When blank, only the attribute existence will be checked for.

      Examples

      Using with the drill API

      const { m, drill } = require('react-drill');
      
      drill(myComponent)
        .find(Button, m.hasAttribute('disabled', false))
          .click()
      ;

    hasClass(className: String) -> Matcher

    Create a matcher function that tests a DOM node for containing a certain CSS class.

    Parameters (1)

    className
    String

    The CSS class you are expecting the Node to contain.

      Examples

      Using with the drill API

      const { m, drill } = require('react-drill');
      
      drill(myComponent)
        .find(Button, m.hasClass('btn--danger'))
          .click()
      ;

    hasProp(propKey: String, propValue: Any) -> Matcher

    Select a component that has a prop matching the specified value.

    hasProperty(property: String, value: String) -> Matcher

    Create a matcher function that tests a DOM node for having a certain property with a specific value.

    Parameters (2)

    property
    String

    The property name.

    value
    String

    The value name.

      Examples

      Using with the drill API

      const { m, drill } = require('react-drill');
      
      drill(myComponent)
        .find('input', m.hasProperty('value', 'foo'))
          .click()
      ;

    hasText(text: String) -> Matcher

    A matcher for the textContent of a Node.

    Parameters (1)

    text
    String

    The text, or a part of it, you are expecting.

      Examples

      Using with the drill API

      const { m, drill } = require('react-drill');
      
      drill(myComponent)
        .find(Button, m.hasText('Remove User'))
          .click()
      ;

Type Definitions

    Matcher(
      domNode: HTMLElement,
      index: Number,
      props: Object?
    )
    -> Boolean