objectmodel 4.4.2 → 4.4.4

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.
@@ -1,4 +1,4 @@
1
- import {expectType} from 'tsd';
1
+ import {expectError, expectType} from 'tsd';
2
2
  import { ObjectModel } from '../src/object-model';
3
3
  import { MapModel } from '../src/map-model';
4
4
 
@@ -18,4 +18,9 @@ expectType<Map<string | number | { ref: string }, Date | string | { date: Date }
18
18
  ["a", new Date()],
19
19
  [2, "b"],
20
20
  [{ ref: "c"}, { date: new Date() }]
21
- ]))
21
+ ]))
22
+
23
+ const M = MapModel(Number, String).defaultTo(new Map([[1, "first"]]))
24
+ expectType<Map<number, string>>(new M())
25
+ expectError(MapModel(Number, String).defaultTo("not a map"))
26
+ expectError(M("not a map"))
@@ -50,4 +50,33 @@ ann = new ClassMother({ name: "Ann", child: joanna })
50
50
 
51
51
  expectType<ClassMother>(ann)
52
52
  expectType<string>(ann.name)
53
- expectType<ClassPerson>(ann.child)
53
+ expectType<ClassPerson>(ann.child)
54
+
55
+ const FileInfo = ObjectModel({
56
+ name: String,
57
+ size: [Number],
58
+ creationDate: [Date],
59
+ writable: Boolean
60
+ }).defaultTo({
61
+ name: "Untitled file",
62
+ size: 0,
63
+ writable: true
64
+ });
65
+
66
+ expectType<{
67
+ name: string,
68
+ size: number,
69
+ writable: true
70
+ }>(new FileInfo())
71
+
72
+ expectType<{
73
+ name: string,
74
+ size: number,
75
+ writable: boolean,
76
+ creationDate: Date
77
+ }>(new FileInfo({
78
+ name: "My file",
79
+ size: 100,
80
+ writable: false,
81
+ creationDate: new Date()
82
+ }))
@@ -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) {
@@ -1,4 +1,4 @@
1
- import {expectType} from 'tsd';
1
+ import {expectError, expectType} from 'tsd';
2
2
  import { ObjectModel } from '../src/object-model';
3
3
  import { SetModel } from '../src/set-model';
4
4
 
@@ -14,4 +14,9 @@ expectType<Set<{ answer: number } | string | boolean>>(Quiz(new Set()));
14
14
 
15
15
  const SetModel1 = SetModel(String)
16
16
  const SetModel2 = SetModel1.extend(Date, Number)
17
- expectType<Set<string | Date | number>>(SetModel2([1,"2",new Date()]))
17
+ expectType<Set<string | Date | number>>(SetModel2([1,"2",new Date()]))
18
+
19
+ const S = SetModel(Number).defaultTo(new Set([1,2,3]))
20
+ expectType<Set<number>>(S())
21
+ expectError(SetModel(Number).defaultTo("not a set"))
22
+ expectError(S("not a number"))