Skip to content

Commit

Permalink
should work with el in context or args
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Jun 15, 2015
1 parent 5fb1035 commit d68e485
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var is = require('is')

module.exports = function attr(d, name, value) {
d = d.node ? d.node() : d
if (is.str(d)) return function(el){ return attr(el, d) }
if (is.str(d)) return function(el){ return attr(this.nodeName || this.node ? this : el, d) }

return arguments.length > 2 && value === false ? d.removeAttribute(name)
: arguments.length > 2 ? d.setAttribute(name, value)
Expand Down
7 changes: 6 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('attr', function() {

before(function(){
/* istanbul ignore else */
if (!client) return el =require("jsdom")
if (!client) return el = require("jsdom")
.jsdom('<div key="value">')
.defaultView
.document
Expand Down Expand Up @@ -54,4 +54,9 @@ describe('attr', function() {
expect(attr(el, 'baz')).to.eql(null)
})

it('should work curried', function() {
expect(attr('key')(el)).to.eql('value')
expect(attr('key').call(el)).to.eql('value')
})

})

0 comments on commit d68e485

Please sign in to comment.