deku-component-find-all

1.0.1 • Public • Published

deku-component-find-all Build Status

Traverse a Deku component tree and return all components that satisfy a function.

Inspired by react-shallow-testutils

Example

import findAll from 'deku-component-find-all'
import element from 'virtual-element'
import Mock from 'component-mock'

const Component = {
  render: function () {
    element('ul', [
      element('li', 'Foo'),
      element('li', 'Bar')
    ])
  }
}

const mock = Mock(component)
const node = mock.render()

let listElement = findAll(node, (element) => {
  return element.children.length === 2
})

listElement = listElement[0]

console.log(listElement.type) //=> returns `ul`

const listItems = findAll(node, (element) => {
  return element.type === 'li'
})

console.log(listItems.length) //=> returns `2`

API

findAll(node, fn)

Returns an array of items found within node that satisfy fn.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i deku-component-find-all

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • kvnneff