');
expect($elem).to.have.length(0);
});
it('should be able to select multiple elements: $(".apple, #fruits")', function() {
var $elems = $('.apple, #fruits', fruits);
expect($elems).to.have.length(2);
var $apple = _.filter($elems, function(elem) {
return elem.attribs['class'] === 'apple';
});
var $fruits = _.filter($elems, function(elem) {
return elem.attribs.id === 'fruits';
});
testAppleSelect($apple);
expect($fruits[0].attribs.id).to.equal('fruits');
});
it('should select first element $(:first)');
// var $elem = $(':first', fruits);
// var $h2 = $('
fruits
');
// console.log($elem.before('hi'));
// console.log($elem.before($h2));
it('should be able to select immediate children: $("#fruits > .pear")', function() {
var $food = $(food);
$('.pear', $food).append('
Another Pear!');
expect($('#fruits .pear', $food)).to.have.length(2);
var $elem = $('#fruits > .pear', $food);
expect($elem).to.have.length(1);
expect($elem.attr('class')).to.equal('pear');
});
it('should be able to select immediate children: $(".apple + .pear")', function() {
var $elem = $('.apple + li', fruits);
expect($elem).to.have.length(1);
$elem = $('.apple + .pear', fruits);
expect($elem).to.have.length(0);
$elem = $('.apple + .orange', fruits);
expect($elem).to.have.length(1);
expect($elem.attr('class')).to.equal('orange');
});
it('should be able to select immediate children: $(".apple ~ .pear")', function() {
var $elem = $('.apple ~ li', fruits);
expect($elem).to.have.length(2);
$elem = $('.apple ~ .pear', fruits);
expect($elem.attr('class')).to.equal('pear');
});
it('should handle wildcards on attributes: $("li[class*=r]")', function() {
var $elem = $('li[class*=r]', fruits);
expect($elem).to.have.length(2);
expect($elem.eq(0).attr('class')).to.equal('orange');
expect($elem.eq(1).attr('class')).to.equal('pear');
});
it('should handle beginning of attr selectors: $("li[class^=o]")', function() {
var $elem = $('li[class^=o]', fruits);
expect($elem).to.have.length(1);
expect($elem.eq(0).attr('class')).to.equal('orange');
});
it('should handle beginning of attr selectors: $("li[class$=e]")', function() {
var $elem = $('li[class$=e]', fruits);
expect($elem).to.have.length(2);
expect($elem.eq(0).attr('class')).to.equal('apple');
expect($elem.eq(1).attr('class')).to.equal('orange');
});
it('should gracefully degrade on complex, unmatched queries', function() {
var $elem = $('Eastern States Cup #8-fin
Downhill ');
expect($elem).to.have.length(0); // []
});
it('(extended Array) should not interfere with prototype methods (issue #119)', function() {
var extended = [];
var custom = extended.find = extended.children = extended.each = function() {};
var $empty = $(extended);
expect($empty.find).to.be($.prototype.find);
expect($empty.children).to.be($.prototype.children);
expect($empty.each).to.be($.prototype.each);
});
it('should render xml in html() when options.xmlMode = true', function() {
var str = '
',
expected = '
',
dom = $.load(str, {xmlMode: true});
expect(dom('MixedCaseTag').get(0).name).to.equal('MixedCaseTag');
expect(dom.html()).to.be(expected);
});
it('should render xml in html() when options.xmlMode = true passed to html()', function() {
var str = '
',
// since parsing done without xmlMode flag, all tags converted to lowercase
expectedXml = '
',
expectedNoXml = '
',
dom = $.load(str);
expect(dom('MixedCaseTag').get(0).name).to.equal('mixedcasetag');
expect(dom.html()).to.be(expectedNoXml);
expect(dom.html({xmlMode: true})).to.be(expectedXml);
});
it('should respect options on the element level', function() {
var str = '
Some test',
expectedHtml = '
Copyright © 2003-2014
',
expectedXml = '
Copyright © 2003-2014
',
domNotEncoded = $.load(str, {decodeEntities: false}),
domEncoded = $.load(str);
expect(domNotEncoded('footer').html()).to.be(expectedHtml);
// TODO: Make it more html friendly, maybe with custom encode tables
expect(domEncoded('footer').html()).to.be(expectedXml);
});
});