Skip to content

Commit

Permalink
Fix attr when $ collection contains text modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Feb 28, 2014
1 parent 18bc828 commit f8e3419
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ var attr = exports.attr = function(name, value) {
});
}
return domEach(this, function(i, el) {
if (!isTag(el)) return;

if (typeof name === 'object') {
_.each(name, function(name, key) {
el.attribs[key] = name+'';
Expand Down
8 changes: 8 additions & 0 deletions test/api.attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('$(...)', function() {
expect($pear.cheerio).to.not.be(undefined);
});

it('(key, value) : should set attr', function() {
var $el = $('<div></div> <div></div>').attr('class', 'pear');

expect($el[0].attribs['class']).to.equal('pear');
expect($el[1].attribs).to.equal(undefined);
expect($el[2].attribs['class']).to.equal('pear');
});

it('(key, value) : should return an empty object for an empty object', function() {
var $src = $().attr('key', 'value');
expect($src.length).to.equal(0);
Expand Down

0 comments on commit f8e3419

Please sign in to comment.