@@ -134,4 +134,74 @@ describe('.bindDirective', () => {
134
134
expect ( el . title ) . toEqual ( 'test' ) ;
135
135
expect ( el . translate ) . toEqual ( null ) ;
136
136
} ) ;
137
+
138
+ it ( 'should accept string format for attributes' , ( ) => {
139
+ const el = document . createElement ( 'a' ) ;
140
+ const expression = 'foo' ;
141
+ const state = { foo : expression } ;
142
+ bindDirective ( {
143
+ el,
144
+ parts : [ 'bind' , 'title' ] ,
145
+ data : {
146
+ value : expression ,
147
+ compute : compute ( expression , el ) ,
148
+ deps : [ 'title' ] ,
149
+ } ,
150
+ state,
151
+ } ) ;
152
+ expect ( el . getAttribute ( 'title' ) ) . toEqual ( 'foo' ) ;
153
+ } ) ;
154
+
155
+ it ( 'should remove attribute if no value apparent' , ( ) => {
156
+ const el = document . createElement ( 'a' ) ;
157
+ const expression = '' ;
158
+ const state = { } ;
159
+ bindDirective ( {
160
+ el,
161
+ parts : [ 'bind' , 'title' ] ,
162
+ data : {
163
+ value : expression ,
164
+ compute : compute ( expression , el ) ,
165
+ deps : [ 'title' ] ,
166
+ } ,
167
+ state,
168
+ } ) ;
169
+ expect ( el . hasAttribute ( 'title' ) ) . toEqual ( false ) ;
170
+ } ) ;
171
+
172
+ it ( 'should remove class attribute if no classes apparent' , ( ) => {
173
+ const el = document . createElement ( 'a' ) ;
174
+ const expression = `{}` ;
175
+ const state = { } ;
176
+ bindDirective ( {
177
+ el,
178
+ parts : [ 'bind' , 'class' ] ,
179
+ data : {
180
+ value : expression ,
181
+ compute : compute ( expression , el ) ,
182
+ deps : [ ] ,
183
+ } ,
184
+ state,
185
+ } ) ;
186
+ expect ( el . className ) . toEqual ( '' ) ;
187
+ expect ( el . hasAttribute ( 'class' ) ) . toEqual ( false ) ;
188
+ } ) ;
189
+
190
+ it ( 'should remove style attribute if no styles apparent' , ( ) => {
191
+ const el = document . createElement ( 'a' ) ;
192
+ el . setAttribute ( 'style' , '' ) ;
193
+ const expression = `{}` ;
194
+ const state = { } ;
195
+ bindDirective ( {
196
+ el,
197
+ parts : [ 'bind' , 'style' ] ,
198
+ data : {
199
+ value : expression ,
200
+ compute : compute ( expression , el ) ,
201
+ deps : [ ] ,
202
+ } ,
203
+ state,
204
+ } ) ;
205
+ expect ( el . hasAttribute ( 'style' ) ) . toEqual ( false ) ;
206
+ } ) ;
137
207
} ) ;
0 commit comments