Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Latest commit

 

History

History
72 lines (53 loc) · 1.34 KB

README.md

File metadata and controls

72 lines (53 loc) · 1.34 KB

vtree-query

Testing utility for the Zorium framework

Install

npm install --save-dev vtree-query

Example

z = require 'zorium'
query = require 'vtree-query'

tree = z 'div', 'test'
$ = query(tree)
$('div').contents.should.be 'test'

tree =
  z 'div',
    z '.class',
      z '#id',
        z 'span',
          'abc'
        z 'span',
          'xyz'

$ = query(tree)
$$ = query.all(tree)

$('div .class #id span').contents.should.be 'abc'
$('span').contents.should.be 'abc'

$$('div .class #id span').length.should.be 2
$$('span').length.should.be 2

# Properties
tree = z 'input', type: 'button'
$ = query tree
$('input').type.should.be 'button'

# Attributes
tree = z 'div',
  z 'a', href: 'abc', 'aaa'

$ = query tree
$('a[href=abc]').contents.should.be 'aaa'

query(vtree, selector)

Returns first matching vNode, with a contents property that contains text info.
This method supports currying

tree = z 'div', 'test'
$ = query(tree)
$('div').contents.should.be 'test'

query.all()

Returns all matching vNodes, with contents properties that contain text info.
This method supports currying

tree = z 'div', 'test'
$$ = query.all(tree)
$$('div')[0].contents.should.be 'test'