@@ -2,13 +2,42 @@ describe('UNIT: Directives', function () {
2
2
3
3
describe ( 'attr' , function ( ) {
4
4
5
- var dir = mockDirective ( 'attr' )
6
- dir . arg = 'href'
5
+ var dir = mockDirective ( 'attr' , 'input' ) ,
6
+ el = dir . el
7
7
8
- it ( 'should set an attribute' , function ( ) {
9
- var url = 'http://a.b.com'
10
- dir . update ( url )
11
- assert . strictEqual ( dir . el . getAttribute ( 'href' ) , url )
8
+ it ( 'should set a truthy attribute value' , function ( ) {
9
+ var value = 'Arrrrrr!'
10
+
11
+ dir . arg = 'value'
12
+ dir . update ( value )
13
+ assert . strictEqual ( el . getAttribute ( 'value' ) , value )
14
+ } )
15
+
16
+ it ( 'should set attribute value to `0`' , function ( ) {
17
+ dir . arg = 'value'
18
+ dir . update ( 0 )
19
+ assert . strictEqual ( el . getAttribute ( 'value' ) , '0' )
20
+ } )
21
+
22
+ it ( 'should remove an attribute if value is `false`' , function ( ) {
23
+ dir . arg = 'disabled'
24
+ el . setAttribute ( 'disabled' , 'disabled' )
25
+ dir . update ( false )
26
+ assert . strictEqual ( el . getAttribute ( 'disabled' ) , null )
27
+ } )
28
+
29
+ it ( 'should remove an attribute if value is `null`' , function ( ) {
30
+ dir . arg = 'disabled'
31
+ el . setAttribute ( 'disabled' , 'disabled' )
32
+ dir . update ( null )
33
+ assert . strictEqual ( el . getAttribute ( 'disabled' ) , null )
34
+ } )
35
+
36
+ it ( 'should remove an attribute if value is `undefined`' , function ( ) {
37
+ dir . arg = 'disabled'
38
+ el . setAttribute ( 'disabled' , 'disabled' )
39
+ dir . update ( undefined )
40
+ assert . strictEqual ( el . getAttribute ( 'disabled' ) , null )
12
41
} )
13
42
14
43
} )
0 commit comments