Skip to content

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

License

Notifications You must be signed in to change notification settings

kvnneff/deku-component-find-all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published