Skip to content

Commit 1a45d08

Browse files
committed
Add another simple test style
Based on // Pulled from 1b54593#diff-a88a95e60b13a839d0277ac5c7605aa092bbf22a5e1f0379b9494bccfd286eb4L98 Starts to highlight the problems with List & Unmanaged
1 parent fb87434 commit 1a45d08

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

packages/realm/type-tests/nested-unmanaged-tests.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,53 @@
2323
import * as BSON from "bson";
2424
import Realm from "realm";
2525

26+
// Simple Unmanaged remapping tests
27+
type MyObj = {
28+
stringProp1: Realm.Types.String;
29+
stringProp2: Realm.Types.String;
30+
nullableStringProp1: Realm.Types.String | null;
31+
nullableStringProp2: Realm.Types.String | null;
32+
stringOrUndefined1?: Realm.Types.String;
33+
stringOrUndefined2?: Realm.Types.String;
34+
35+
listStringProp1: Realm.Types.List<Realm.Types.String>;
36+
listStringProp2: Realm.Types.List<Realm.Types.String>;
37+
listStringProp3: Realm.Types.List<Realm.Types.String>;
38+
nullableListStringProp1: Realm.Types.List<Realm.Types.String> | null;
39+
nullableListStringProp2: Realm.Types.List<Realm.Types.String> | null;
40+
nullableListStringProp3: Realm.Types.List<Realm.Types.String> | null;
41+
listStringOrUndefinedProp1?: Realm.Types.List<Realm.Types.String>;
42+
listStringOrUndefinedProp2?: Realm.Types.List<Realm.Types.String>;
43+
listStringOrUndefinedProp3?: Realm.Types.List<Realm.Types.String>;
44+
};
45+
const test: Realm.Unmanaged<MyObj> = {
46+
stringProp1: "test",
47+
// @ts-expect-error - Expected: invalid
48+
stringProp2: null,
49+
nullableStringProp1: null,
50+
nullableStringProp2: "blah",
51+
stringOrUndefined1: undefined,
52+
stringOrUndefined2: "sad",
53+
54+
someExtraPropertyNotSpecifiedOnMyObj: "string",
55+
56+
listStringProp1: ["test"],
57+
// @ts-expect-error - Expected: invalid
58+
listStringProp2: [1],
59+
// @ts-expect-error - Expected: invalid
60+
listStringProp3: null,
61+
nullableListStringProp1: null,
62+
nullableListStringProp2: ["test"],
63+
// @ts-expect-error - Expected: invalid
64+
nullableListStringProp3: [1],
65+
listStringOrUndefinedProp1: undefined,
66+
listStringOrUndefinedProp2: ["test"],
67+
// @ts-expect-error - Expected: invalid
68+
listStringOrUndefinedProp3: [1],
69+
};
70+
test;
71+
72+
// Extended functionality tests (ensure RequiredProperties work)
2673
class RealmClassWithRequiredParams extends Realm.Object<
2774
RealmClassWithRequiredParams,
2875
| "aMandatoryString"
@@ -120,10 +167,12 @@ const realm = new Realm({ schema: [RealmClassWithRequiredParams, RealmClassWitho
120167
// @ts-expect-error - a String shouldn't be accepted as 'values'
121168
new RealmClassWithRequiredParams(realm, "this shouldn't be accepted");
122169

123-
// FIXME - this doesn't error and it should
124-
// @xxxts-expect-error - a String shouldn't be accepted as 'values'
170+
// TODO - this doesn't error and it should
171+
// should-be-@ts-expect-error - a String shouldn't be accepted as 'values'
125172
new RealmClassWithoutRequiredParams(realm, "this shouldn't be accepted");
126173

174+
// Realm.create() tests
175+
127176
realm.write(() => {
128177
// === Realm.Object classes ===
129178
// @ts-expect-error - Empty object not allowed due to being required params
@@ -150,8 +199,8 @@ realm.write(() => {
150199
realm.create(RealmClassWithoutRequiredParams, new RealmClassWithoutRequiredParams(realm, {}));
151200

152201
// === Unmanaged objects ===
153-
// FIXME - Should this be erroring? The class has required types so shouldn't they be automatically required in the Unmanaged version too? Is this possible
154-
// @xxxts-expect-error - Empty object not allowed due to being required params
202+
// TODO - Should this be erroring? The class has required types so shouldn't they be automatically required in the Unmanaged version too? Is this possible
203+
// should-be-@ts-expect-error - Empty object not allowed due to being required params
155204
realm.create(RealmClassWithRequiredParams, {});
156205

157206
realm.create(RealmClassWithRequiredParams, {

0 commit comments

Comments
 (0)