-
Notifications
You must be signed in to change notification settings - Fork 1
/
setAttribute.coffee
39 lines (38 loc) · 1.02 KB
/
setAttribute.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{isString} = require("./_helpers")
module.exports =
_name: "$setAttribute"
_v: 1
methods:
$setAttribute: (el, name, val) ->
if isString(el)
val = name
name = el
el = @
if val? and val != false and (isString(val) or !isNaN(val))
if val == true
el.setAttribute name, ""
else
el.setAttribute name, val
else
el.removeAttribute name
return then: @$nextTick
test module.exports, {}, (el) ->
it "should set boolean", (done) ->
el.$setAttribute "test", true
.then ->
el.should.have.attr "test", ""
el.$setAttribute "test", false
.then ->
el.should.not.have.attr "test"
done()
it "should set strings", (done) ->
el.$setAttribute "test", "test"
.then ->
el.should.have.attr "test","test"
el.$setAttribute "test", ""
.then ->
el.should.have.attr "test", ""
el.$setAttribute "test", null
.then ->
el.should.not.have.attr "test"
done()