process.mixin(require('express/collection')) process.mixin(require('express/element-collection')) describe 'Express' describe 'ElementCollection' describe '$("markup string")' it 'should return a ElementCollection' $('

foo

').should.be_an_instance_of Collection $('

foo

').should.be_an_instance_of ElementCollection end it 'should wrap with .. when not present' $('

foo

').at(0).name().should.eql 'html' end it 'should not wrap with when already present' $('').at(0).name().should.eql 'html' end end describe '#name()' it 'should return the first elements name' $('').name().should.eql 'html' end end describe '#xpath()' it 'should find children matching the given xpath' $('
  • 1
  • 2
  • ').xpath('descendant-or-self::li').length().should.eql 2 $('
  • 1
  • 2
  • ').xpath('descendant-or-self::li').at(0).name().should.eql 'li' var items = $('
  • Foo

  • Bar

  • ').xpath('descendant-or-self::li') items.xpath('descendant-or-self::p').length().should.eql 2 end end describe '#search()' it 'should find children matching the given css selector' $('').search('ul > li:nth-child(2)').text().should.eql 'bar' end end describe '#children()' it 'should return children' $('

    foobar

    ').children().length().should.eql 1 $('

    foobar

    ').xpath('descendant-or-self::p').children().length().should.eql 2 end end describe '#parents()' it 'should return parents' $('').xpath('descendant-or-self::li').parents().length().should.eql 2 $('').xpath("descendant-or-self::*/*[name() = 'ul' and (position() = 1)]/descendant::li").parents().length().should.eql 1 end end describe '#parent()' it 'should return the first parent' $('').xpath('descendant-or-self::li').parent().length().should.eql 1 end end describe '#text()' it 'should return an elements text' $('

    foo bar

    ').text().should.eql 'foo bar' end end describe '#next()' it 'should return the next element' $('foo

    bar

    ').xpath('descendant-or-self::em').next().text().should.eql 'bar' end end describe '#prev()' it 'should return the previous element' $('foo

    bar

    ').xpath('descendant-or-self::p').prev().text().should.eql 'foo' end end end end