diff --git a/lib/api/manipulation.js b/lib/api/manipulation.js index 670837d3dc..79e3098d08 100644 --- a/lib/api/manipulation.js +++ b/lib/api/manipulation.js @@ -371,7 +371,7 @@ exports.html = function(str) { el.next = el.prev = el.parent = null; }); - var content = str.cheerio ? str.clone().get() : evaluate(str, opts); + var content = str.cheerio ? str.clone().get() : evaluate('' + str, opts); updateDOM(content, el); }); @@ -402,7 +402,7 @@ exports.text = function(str) { }); var elem = { - data: str, + data: '' + str, type: 'text', parent: el, prev: null, diff --git a/test/cheerio.js b/test/cheerio.js index 507422e49d..9a515e80a0 100644 --- a/test/cheerio.js +++ b/test/cheerio.js @@ -227,6 +227,18 @@ describe('cheerio', function() { expect($empty.each).to.be($.prototype.each); }); + it('should set html(number) as a string', function() { + var $elem = $('
'); + $elem.html(123); + expect(typeof $elem.text()).to.equal('string'); + }); + + it('should set text(number) as a string', function() { + var $elem = $('
'); + $elem.text(123); + expect(typeof $elem.text()).to.equal('string'); + }); + describe('.load', function() { it('should generate selections as proper instances', function() {