@@ -15,7 +15,7 @@ describe('jqLite', function() {
15
15
this . addMatchers ( {
16
16
toJqEqual : function ( expected ) {
17
17
var msg = "Unequal length" ;
18
- this . message = function ( ) { return msg ; } ;
18
+ this . message = function ( ) { return msg ; } ;
19
19
20
20
var value = this . actual && expected && this . actual . length == expected . length ;
21
21
for ( var i = 0 ; value && i < expected . length ; i ++ ) {
@@ -191,20 +191,46 @@ describe('jqLite', function() {
191
191
expect ( jqLite ( b ) . attr ( 'prop' ) ) . toBeFalsy ( ) ;
192
192
} ) ;
193
193
194
- it ( 'should read special attributes as strings' , function ( ) {
194
+ it ( 'should read boolean attributes as strings' , function ( ) {
195
195
var select = jqLite ( '<select>' ) ;
196
196
expect ( select . attr ( 'multiple' ) ) . toBeUndefined ( ) ;
197
197
expect ( jqLite ( '<select multiple>' ) . attr ( 'multiple' ) ) . toBe ( 'multiple' ) ;
198
198
expect ( jqLite ( '<select multiple="">' ) . attr ( 'multiple' ) ) . toBe ( 'multiple' ) ;
199
199
expect ( jqLite ( '<select multiple="x">' ) . attr ( 'multiple' ) ) . toBe ( 'multiple' ) ;
200
+ } ) ;
200
201
202
+ it ( 'should add/remove boolean attributes' , function ( ) {
203
+ var select = jqLite ( '<select>' ) ;
201
204
select . attr ( 'multiple' , false ) ;
202
205
expect ( select . attr ( 'multiple' ) ) . toBeUndefined ( ) ;
203
206
204
207
select . attr ( 'multiple' , true ) ;
205
208
expect ( select . attr ( 'multiple' ) ) . toBe ( 'multiple' ) ;
206
209
} ) ;
207
210
211
+ it ( 'should normalize the case of boolean attributes' , function ( ) {
212
+ var input = jqLite ( '<input readonly>' ) ;
213
+ expect ( input . attr ( 'readonly' ) ) . toBe ( 'readonly' ) ;
214
+ expect ( input . attr ( 'readOnly' ) ) . toBe ( 'readonly' ) ;
215
+ expect ( input . attr ( 'READONLY' ) ) . toBe ( 'readonly' ) ;
216
+
217
+ input . attr ( 'readonly' , false ) ;
218
+
219
+ // attr('readonly') fails in jQuery 1.6.4, so we have to bypass it
220
+ //expect(input.attr('readOnly')).toBeUndefined();
221
+ //expect(input.attr('readonly')).toBeUndefined();
222
+ if ( msie < 9 ) {
223
+ expect ( input [ 0 ] . getAttribute ( 'readonly' ) ) . toBe ( '' ) ;
224
+ } else {
225
+ expect ( input [ 0 ] . getAttribute ( 'readonly' ) ) . toBe ( null ) ;
226
+ }
227
+ //expect('readOnly' in input[0].attributes).toBe(false);
228
+
229
+ input . attr ( 'readOnly' , 'READonly' ) ;
230
+ expect ( input . attr ( 'readonly' ) ) . toBe ( 'readonly' ) ;
231
+ expect ( input . attr ( 'readOnly' ) ) . toBe ( 'readonly' ) ;
232
+ } ) ;
233
+
208
234
it ( 'should return undefined for non-existing attributes' , function ( ) {
209
235
var elm = jqLite ( '<div class="any">a</div>' ) ;
210
236
expect ( elm . attr ( 'non-existing' ) ) . toBeUndefined ( ) ;
0 commit comments