Skip to content

Commit 12e8f07

Browse files
committed
Moved the val() tests from manipulation into attributes.
1 parent 4681216 commit 12e8f07

File tree

2 files changed

+86
-86
lines changed

2 files changed

+86
-86
lines changed

test/unit/attributes.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,92 @@ test("attr('tabindex', value)", function() {
292292
equals(element.attr('tabindex'), -1, 'set negative tabindex');
293293
});
294294

295+
test("val()", function() {
296+
expect(17);
297+
298+
document.getElementById('text1').value = "bla";
299+
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
300+
301+
reset();
302+
303+
equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
304+
// ticket #1714 this caused a JS error in IE
305+
equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
306+
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
307+
308+
equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
309+
310+
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
311+
312+
equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
313+
314+
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
315+
316+
equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
317+
318+
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
319+
320+
jQuery('#select3').val("");
321+
same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
322+
323+
var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
324+
.add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
325+
.add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
326+
.add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
327+
328+
same( checks.serialize(), "", "Get unchecked values." );
329+
330+
equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
331+
332+
checks.val([ "2" ]);
333+
same( checks.serialize(), "test=2", "Get a single checked value." );
334+
335+
checks.val([ "1", "" ]);
336+
same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
337+
338+
checks.val([ "", "2" ]);
339+
same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
340+
341+
checks.val([ "1", "on" ]);
342+
same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
343+
344+
checks.remove();
345+
});
346+
347+
var testVal = function(valueObj) {
348+
expect(6);
349+
350+
jQuery("#text1").val(valueObj( 'test' ));
351+
equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
352+
353+
jQuery("#text1").val(valueObj( 67 ));
354+
equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
355+
356+
jQuery("#select1").val(valueObj( "3" ));
357+
equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
358+
359+
jQuery("#select1").val(valueObj( 2 ));
360+
equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
361+
362+
jQuery("#select1").append("<option value='4'>four</option>");
363+
jQuery("#select1").val(valueObj( 4 ));
364+
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
365+
366+
// using contents will get comments regular, text, and comment nodes
367+
var j = jQuery("#nonnodes").contents();
368+
j.val(valueObj( "asdf" ));
369+
equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
370+
j.removeAttr("value");
371+
}
372+
373+
test("val(String/Number)", function() {
374+
testVal(bareObj);
375+
});
376+
377+
test("val(Function)", function() {
378+
testVal(functionReturningObj);
379+
})
380+
295381
var testAddClass = function(valueObj) {
296382
expect(2);
297383
var div = jQuery("div");

test/unit/manipulation.js

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -618,92 +618,6 @@ test("clone() on XML nodes", function() {
618618
});
619619
}
620620

621-
test("val()", function() {
622-
expect(17);
623-
624-
document.getElementById('text1').value = "bla";
625-
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
626-
627-
reset();
628-
629-
equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
630-
// ticket #1714 this caused a JS error in IE
631-
equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
632-
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
633-
634-
equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
635-
636-
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
637-
638-
equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
639-
640-
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
641-
642-
equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
643-
644-
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
645-
646-
jQuery('#select3').val("");
647-
same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
648-
649-
var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
650-
.add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
651-
.add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
652-
.add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
653-
654-
same( checks.serialize(), "", "Get unchecked values." );
655-
656-
equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
657-
658-
checks.val([ "2" ]);
659-
same( checks.serialize(), "test=2", "Get a single checked value." );
660-
661-
checks.val([ "1", "" ]);
662-
same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
663-
664-
checks.val([ "", "2" ]);
665-
same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
666-
667-
checks.val([ "1", "on" ]);
668-
same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
669-
670-
checks.remove();
671-
});
672-
673-
var testVal = function(valueObj) {
674-
expect(6);
675-
676-
jQuery("#text1").val(valueObj( 'test' ));
677-
equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
678-
679-
jQuery("#text1").val(valueObj( 67 ));
680-
equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
681-
682-
jQuery("#select1").val(valueObj( "3" ));
683-
equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
684-
685-
jQuery("#select1").val(valueObj( 2 ));
686-
equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
687-
688-
jQuery("#select1").append("<option value='4'>four</option>");
689-
jQuery("#select1").val(valueObj( 4 ));
690-
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
691-
692-
// using contents will get comments regular, text, and comment nodes
693-
var j = jQuery("#nonnodes").contents();
694-
j.val(valueObj( "asdf" ));
695-
equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
696-
j.removeAttr("value");
697-
}
698-
699-
test("val(String/Number)", function() {
700-
testVal(bareObj);
701-
});
702-
703-
test("val(Function)", function() {
704-
testVal(functionReturningObj);
705-
})
706-
707621
var testHtml = function(valueObj) {
708622
expect(22);
709623

0 commit comments

Comments
 (0)