var expect = require('expect.js'), fixtures = require('./fixtures'), $ = require('../'); describe('$', function() { describe('.html', function() { it('() : should return innerHTML; $.html(obj) should return outerHTML', function() { var $div = $('div', '
foobar
'); var span = $div.children()[1]; expect($(span).html()).to.equal('bar'); expect($.html(span)).to.equal('bar'); }); it('() : should accept an object, an array, or a cheerio object', function() { var $span = $('foo'); expect($.html($span[0])).to.equal('foo'); expect($.html($span)).to.equal('foo'); }); it('() : should be able to set to an empty string', function() { var $elem = $('foo').html(''); expect($.html($elem)).to.equal(''); }); it('() : of empty cheerio object should return null', function() { expect($().html()).to.be(null); }); it('(selector) : should return the outerHTML of the selected element', function() { var _$ = $.load(fixtures.fruits); expect(_$.html('.pear')).to.equal('
  • Pear
  • '); }); }); describe('.load', function() { it('(html) : should retain original root after creating a new node', function() { var $html = $.load(''); expect($html('body')).to.have.length(1); $html('', { xmlMode : true }); // console.log($html('script')[0].type); // expect($html('script')[0].type).to.be('tag'); // }); }); describe('.clone', function() { it('() : should return a copy', function() { var $src = $('
    foobarbaz
    ').children(); var $elem = $src.clone(); expect($elem.length).to.equal(3); expect($elem.parent().length).to.equal(1); expect($elem.parent()[0].type).to.equal('root'); expect($elem.text()).to.equal($src.text()); $src.text('rofl'); expect($elem.text()).to.not.equal($src.text()); }); }); describe('.root', function() { it('() : should return a cheerio-wrapped root object', function() { var $html = $.load('
    foobar
    '); $html.root().append('
    '); expect($html.html()).to.equal('
    foobar
    '); }); }); });