Skip to content

Commit

Permalink
test: Adds test 'formToArray: text promotion for missing value attrib…
Browse files Browse the repository at this point in the history
…utes'
  • Loading branch information
kevindb committed Mar 7, 2017
1 parent d566b4b commit 911efdf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 14 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
<input name="f" type="text">
<input type="reset" name="resetButton" value="Reset">
</div></form>

<!-- form6, 'option' testing -->
<form id="form6" action="text.php" method="get"><div>
<select name="A">
<option value="" selected="selected">EMPTY_STRING</option> <!-- TEST A: value === empty string -->
</select>
<select name="B">
<option selected="selected">MISSING_ATTR</option> <!-- TEST B: no value attr -->
</select>
<select name="C" multiple="multiple">
<option value="" selected="selected">EMPTY_STRING</option>
<option selected="selected">MISSING_ATTR</option>
</select>
</div></form>
</div>


Expand Down
26 changes: 21 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ describe('form', function() {
});

it('formToArray: semantic test', function() {
var formData = $('#form2').formToArray(true);
var testData = ['a','b','c','d','e','f'];
for (var i=0; i < 6; i++) {
assert.strictEqual(formData[i].name, testData[i], 'match value at index=' + i);
}
var formData = $('#form2').formToArray(true);
var testData = ['a','b','c','d','e','f'];
for (var i=0; i < 6; i++) {
assert.strictEqual(formData[i].name, testData[i], 'match value at index=' + i);
}
});

it('formToArray: text promotion for missing value attributes', function() {
var expected = [
{ name: 'A', value: ''},
{ name: 'B', value: 'MISSING_ATTR'},
{ name: 'C', value: ''},
{ name: 'C', value: 'MISSING_ATTR'}
];
var a = $('#form6').formToArray(true);

// verify all the option values
for (var i=0; i < a.length; i++) {
assert.strictEqual(a[i].name, expected[i].name, 'Name: ' + a[i].name + ' = ' + expected[i].name);
assert.strictEqual(a[i].value, expected[i].value, 'Value: ' + a[i].value + ' = ' + expected[i].value);
}
});
});

0 comments on commit 911efdf

Please sign in to comment.