Skip to content

Commit ec286e6

Browse files
committed
Add fix for async object-creation / null bug (related to #144)
1 parent 33132d9 commit ec286e6

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

express-site

jsonary/schemaset.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ SchemaList.prototype = {
10981098
origValue = callback;
10991099
callback = tmp;
11001100
}
1101-
if (typeof origValue !== 'undefined' && (typeof origValue !== 'object' || Array.isArray(origValue))) {
1101+
if (typeof origValue !== 'undefined' && (!origValue || typeof origValue !== 'object' || Array.isArray(origValue))) {
11021102
if (callback) callback(undefined);
11031103
return undefined;
11041104
}

tests/tests/04 - Default values and data creation/05 - using existing data.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ tests.add("defining array items to match original", function () {
9292
return true;
9393
});
9494

95-
9695
tests.add("defining array items, ignoring existing data", function () {
9796
var thisTest = this;
9897
var schema1 = Jsonary.createSchema({
@@ -105,6 +104,22 @@ tests.add("defining array items, ignoring existing data", function () {
105104
});
106105
});
107106

107+
tests.add("defining object, with null as existing data", function () {
108+
var thisTest = this;
109+
var schema1 = Jsonary.createSchema({
110+
type: "object",
111+
properties: {
112+
"foo": {type: "boolean"}
113+
},
114+
required: ["foo"]
115+
});
116+
var origData = null;
117+
schema1.createValue(origData, function (createdData) {
118+
thisTest.assert(typeof createdData.foo === 'boolean', "data.foo is a boolean");
119+
thisTest.pass();
120+
});
121+
});
122+
108123
tests.add("defining object properties inside array items (no constraints)", function () {
109124
var schema1 = Jsonary.createSchema({
110125
type: "array",

0 commit comments

Comments
 (0)