Skip to content

Commit

Permalink
fixing missing prop(‘outerHTML’) implementation.
Added an ‘outerHTML’…
Browse files Browse the repository at this point in the history
… case to the switch in the prop function, which wraps a clone of in a container element, and sets to that container's HTML (#945)
  • Loading branch information
bill-bishop authored and fb55 committed Mar 11, 2018
1 parent f7e05b5 commit 2c7a9e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ exports.prop = function (name, value) {
case 'nodeName':
property = this[0].name.toUpperCase();
break;
case 'outerHTML':
property = this.clone().wrap('<container />').parent().html();
break;
default:
property = getProp(this[0], name);
}
Expand Down
9 changes: 9 additions & 0 deletions test/cheerio.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,14 @@ describe('cheerio', function() {
expect($b('div').foo).to.be(undefined);
});
});

describe('.prop', function () {
describe('("outerHTML")', function () {
var outerHtml = '<div><a></a></div>';
var $a = $(outerHtml);

expect($a.prop('outerHTML')).to.be(outerHtml);
});
});
});
});

0 comments on commit 2c7a9e1

Please sign in to comment.