Skip to content

Commit

Permalink
ADD: auto buffer -> string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Feb 15, 2011
1 parent 666442e commit 519fb78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/jsdom.js
Expand Up @@ -15,6 +15,8 @@ exports.__defineGetter__('version', function() {
});

exports.jsdom = function (html, level, options) {
html += '';

options = options || {};
level = level || exports.defaultLevel;

Expand Down Expand Up @@ -55,6 +57,7 @@ exports.jsdom = function (html, level, options) {
};

exports.html = function(html, level, options) {
html += '';
// body
if (!~html.indexOf('<body')) {
html = '<body>' + html + '</body>';
Expand Down Expand Up @@ -150,8 +153,8 @@ exports.jQueryify = exports.jsdom.jQueryify = function (window /* path [optional


exports.env = exports.jsdom.env = function(config, callback) {

var self = this;
config.html += '';

if(!config || !callback) {
throw new Error('JSDOM: a config and callback must be supplied.');
Expand Down
17 changes: 17 additions & 0 deletions test/jsdom/index.js
Expand Up @@ -341,5 +341,22 @@ bye = bye + "bye";\
assertTrue("Element stringify", "9" === a.innerHTML);
assertTrue("Attribute stringify",
"123" === a.getAttributeNode('id').nodeValue);
},
auto_tostring : function() {
var fs = require("fs"),
buffer = fs.readFileSync(__dirname + "/files/env.html"),
caught = false,
dom = null,
count = 0;

try {
dom = jsdom.jsdom(buffer);
} catch (e) {
caught = true;
}

assertFalse("buffer's should automatically be stringified", caught);
count = dom.documentElement.getElementsByTagName("*").length;
assertEquals("should parse as per usual", count, 3)
}
};

0 comments on commit 519fb78

Please sign in to comment.