spec.element-collection.js
This file
Path
spec/spec.element-collection.js
83 lines · 2.8 KiB · JavaScript
Last changed by
Added ElementChildren#search() with css2xpathvisionmediabefore adoptionbf4b189
History of this fileTake it
Renaming a specvisionmediabefore adoption4fa345d
lines 1–37why, one step back12process.mixin(require('express/collection'))3process.mixin(require('express/element-collection'))45describe 'Express'6 describe 'ElementCollection'7 8 describe '$("markup string")'9 it 'should return a ElementCollection'10 $('<p>foo</p>').should.be_an_instance_of Collection11 $('<p>foo</p>').should.be_an_instance_of ElementCollection12 end13 14 it 'should wrap with <html><body>.. when not present'15 $('<p>foo</p>').at(0).name().should.eql 'html'16 end17 18 it 'should not wrap with <html><body> when already present'19 $('<html><body></body></html>').at(0).name().should.eql 'html'20 end21 end22 23 describe '#name()'24 it 'should return the first elements name'25 $('<html><body></body></html>').name().should.eql 'html'26 end27 end28 29 describe '#xpath()'30 it 'should find children matching the given xpath'31 $('<li>1</li><li>2</li>').xpath('descendant-or-self::li').length().should.eql 232 $('<li>1</li><li>2</li>').xpath('descendant-or-self::li').at(0).name().should.eql 'li'33 var items = $('<li><p>Foo</p></li><li><p>Bar</p></li>').xpath('descendant-or-self::li')34 items.xpath('descendant-or-self::p').length().should.eql 235 end36 end37 Added ElementChildren#search() with css2xpathvisionmediabefore adoptionbf4b189
lines 38–43why, one step back38 describe '#search()'39 it 'should find children matching the given css selector'40 $('<ul><li>foo</li><li>bar</li></ul>').search('ul > li:nth-child(2)').text().should.eql 'bar'41 end42 end43 Added ElementCollection#{parents,children}()visionmediabefore adoption1da424a
lines 44–57why, one step back44 describe '#children()'45 it 'should return children'46 $('<p><em>foo</em><strong>bar</strong></p>').children().length().should.eql 147 $('<p><em>foo</em><strong>bar</strong></p>').xpath('descendant-or-self::p').children().length().should.eql 248 end49 end50 51 describe '#parents()'52 it 'should return parents'53 $('<ul><li></li></ul><ul><li></li></ul>').xpath('descendant-or-self::li').parents().length().should.eql 254 $('<ul><li></li></ul><ul><li></li></ul>').xpath("descendant-or-self::*/*[name() = 'ul' and (position() = 1)]/descendant::li").parents().length().should.eql 155 end56 end57 Added ElementCollection#text()visionmediabefore adoptiona5ca9d8
line 58why, one step back58 describe '#parent()'Added ElementCollection#parent()visionmediabefore adoptiond1b7340
lines 59–60why, one step back59 it 'should return the first parent'60 $('<ul><li></li></ul><ul><li></li></ul>').xpath('descendant-or-self::li').parent().length().should.eql 1Added ElementCollection#text()visionmediabefore adoptiona5ca9d8
lines 61–66why, one step back61 end62 end63 64 describe '#text()'65 it 'should return an elements text'66 $('<p>foo bar</p>').text().should.eql 'foo bar'Added ElementCollection#parent()visionmediabefore adoptiond1b7340
lines 67–69why, one step back67 end68 end69 Added ElementCollection#{prev,next}()visionmediabefore adoption28ee0d2
lines 70–81why, one step back70 describe '#next()'71 it 'should return the next element'72 $('<em>foo</em><p>bar</p>').xpath('descendant-or-self::em').next().text().should.eql 'bar'73 end74 end75 76 describe '#prev()'77 it 'should return the previous element'78 $('<em>foo</em><p>bar</p>').xpath('descendant-or-self::p').prev().text().should.eql 'foo'79 end80 end81 Renaming a specvisionmediabefore adoption4fa345d
lines 82–83why, one step back82 end83end