drill Function

Drill into a rendered component and start kicking. This is the main export of the library.

Signature

drill(component: React.Component) -> Scope

import { drill } from 'react-drill'
import Menu from './Menu'

const component = ReactDOM.render(Menu, document.createElement('div'))

drill(component)
  .find('button', m.hasText('Logout'))
    .click()

Static Methods

    drillIntoNode(domNode: HTMLElement | Any) -> Scope

    An esoteric API for drilling into an HTML node without a corresponding React component. Useful if you just want to use the Selectors and Actions on plain HTML nodes or custom ones like Cheerio.

    import { drillIntoNode } from 'react-drill'
    import $ from 'cheerio'
    
    drillIntoNode($('div'))
      .click()

    If you're using Cheerio be sure to use the addon too.

    registerAction(name: String, action: Function)

    Add a new action that will be available on the scope API. Refer to this example for implementing a custom action.

    Parameters (2)

    name
    String

    The name by which we should expose the action on the Scope API.

    action
    Function

    The actual action implementation.

    registerDOMInterface(name: String, fn: Function)

    Advanced for use by addons to override the default DOM operations which are normally handled by jQuery. See DOM.

    registerExtension(name: String, fn: () -> Scope)

    Add a new API for Scope. This is useful for extending the scope with functionality other than actions like custom warp routines.

    The teleporting example shows this in practice.

    Parameters (2)

    name
    String

    The name to use for the API.

    fn
    () -> Scope

    The function MUST return a scope (new or itself.)

    registerMatcher(name: String, fn: Function)

    Register a new matcher that can be accessed through the m exported symbol of the package. Refer to this example for implementing one.

    Parameters (2)

    name
    String

    The name to register the matcher to.

    fn
    Function

    The matcher function.

    registerSelector(name: String, fn: Function)

    Override an existing selector to use a different driver than jQuery (e.g. cheerio).

    Parameters (2)

    name
    String

    The name of the selector (like findAll).

    fn
    Function

    The selector function.

Static Properties

Actions: Actions

DEPRECATED

Use of these APIs without a Scope is discouraged and support for it will be dropped in the future.

A stand-alone version of the DOM helpers to be used without the drilling API.

Matchers: Matchers

Alias to drill.m.

Scope: Scope
Selectors: Selectors

DEPRECATED

Use of these APIs without a Scope is discouraged and support for it will be dropped in the future.

A stand-alone version of the DOM selectors to be used without the drilling API.

drill: drill

A convenience shortcut to the drill function when you are using ES6 destructuring.

For example, the following all work and are equivalent:

// [1]
import { drill, m } from 'react-drill'
// [2]
import drill, { m } from 'react-drill'
// [3]
const { drill, m } = require('react-drill')
// [4]
const drill = require('react-drill')
const { m } = drill
m: Matchers

A shortcut property to access the available Matchers.