Skip to content

Commit

Permalink
fix(load): Support passing a single element (#1580)
Browse files Browse the repository at this point in the history
Fixes #1577
  • Loading branch information
fb55 committed Dec 22, 2020
1 parent f7cae99 commit 0855be6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/parse.js
Expand Up @@ -35,9 +35,9 @@ exports = module.exports = function parse(content, options, isDocument) {
} else {
// Generic root element
var root = new domhandler.Document(content);
content.forEach(function (node) {
node.parent = root;
});

// Update the DOM using the root
exports.update(content, root);

dom = root;
}
Expand Down
7 changes: 7 additions & 0 deletions test/cheerio.js
Expand Up @@ -262,6 +262,13 @@ describe('cheerio', function () {
expect($('ul')).to.have.length(3);
});

it('should allow loading a single element', function () {
var el = htmlparser2.parseDOM(food)[0];
var $ = cheerio.load(el);

expect($('ul')).to.have.length(3);
});

it('should render xml in html() when options.xml = true', function () {
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>';
var expected = '<MixedCaseTag UPPERCASEATTRIBUTE=""/>';
Expand Down

0 comments on commit 0855be6

Please sign in to comment.