-
Notifications
You must be signed in to change notification settings - Fork 351
/
encode-test.js
37 lines (29 loc) · 1.54 KB
/
encode-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var assert = chai.assert;
describe("encode", function() {
it("checkbox inputs as booleans if no value is present", function() {
var $form = $('<form><input type="checkbox" name="a" checked></form>');
assert.deepEqual($form.serializeObject(), {a: true});
});
it("checkbox inputs as strings if other value is present", function() {
var $form = $('<form><input type="checkbox" name="a" value="b" checked></form>');
assert.deepEqual($form.serializeObject(), {a: "b"});
});
it("checkbox inputs with deep keys don't break", function() {
var $form = $('<form><input type="checkbox" name="a[b][c]" checked></form>');
assert.deepEqual($form.serializeObject(), {a: {b: {c: true}}});
});
it("checkbox inputs as booleans if value is 'on'", function() {
var $form = $('<form><input type="checkbox" name="a" value="on" checked></form>');
assert.deepEqual($form.serializeObject(), {a: true});
});
it("non-checkbox input as string if value is 'on'", function() {
var $form = $('<form><input name="a" value="on" checked></form>');
assert.deepEqual($form.serializeObject(), {a: "on"});
});
it("should pass issue #107", function() {
var $form1 = $('<form id="f1"><input name="a" type="radio" value="0" checked/><input name="a" type="radio" value="-1"/></form>');
var $form2 = $('<form id="f2"><input name="a" type="radio" value="1" checked/><input name="a" type="radio" value="2"/></form>');
assert.deepEqual($form1.serializeObject(), {a: "0"});
assert.deepEqual($form2.serializeObject(), {a: "1"});
});
});