objectmodel 4.4.1 → 4.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1343,4 +1343,27 @@ QUnit.test("Short-circuit validation when not receiving an object as expected",
1343
1343
  FirstName: String,
1344
1344
  LastName: String
1345
1345
  }, got Number 42`)
1346
+ })
1347
+
1348
+ QUnit.test("Deep nesting and model defaults", function(assert){
1349
+ const Address = new Model({
1350
+ street: String,
1351
+ number: String,
1352
+ }).defaultTo({
1353
+ number: "unknown number",
1354
+ });
1355
+
1356
+ const Person = new Model({
1357
+ name: String,
1358
+ address: Address,
1359
+ }).defaultTo({
1360
+ name: "Unknown name",
1361
+ });
1362
+
1363
+ const Register = new Model({
1364
+ person: Person,
1365
+ });
1366
+
1367
+ const reg = new Register({ person: { address: { street: "unknown street" } } });
1368
+ assert.equal(reg.person.address.number, "unknown number", "deep nested models should apply defaults on missing parent")
1346
1369
  })
@@ -148,6 +148,15 @@ QUnit.test("defaults values", function (assert) {
148
148
 
149
149
  })
150
150
 
151
+ QUnit.test("validate defaut values provided", function (assert) {
152
+ assert.throws(function () {
153
+ SetModel(Number).defaultTo()
154
+ }, /TypeError.*expecting Set of Number, got undefined*/, "invalid default value provided: undefined");
155
+ assert.throws(function () {
156
+ SetModel(Number).defaultTo(new Set(["foo", "bar"]))
157
+ }, /TypeError.*expecting Set value to be Number, got String \"foo\"*/, "invalid default value provided: wrong type");
158
+ })
159
+
151
160
  QUnit.test("assertions", function (assert) {
152
161
 
153
162
  const SetMax3 = SetModel(String).assert(function maxEntries(set) {