Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions integration-tests/tests/src/tests/shared-realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,64 @@ describe("SharedRealm operations", () => {
expect(this.realm.objectForPrimaryKey("Person", "Bob")).primaryKey.equals("Bob");
});
});

describe("Number conversion", () => {
beforeEach(() => {
Realm.clearTestState();
});

it("Int field does not accept Infinity", async () => {
const IntSchema = {
name: "IntSchema",
properties: {
id: "int",
number: "int",
},
primaryKey: "id",
};

const realm = await Realm.open({
inMemory: true,
schema: [IntSchema],
});

// Infinity is not a valid integer. Node and RN throw different error messages so we only
// check if throws.
// node: "The number Infinity cannot be converted to a BigInt because it is not an integer"
// RN: "number is not integral"
expect(() => {
realm.write(() => {
realm.create(IntSchema.name, {
id: 1,
number: Infinity,
});
});
}).to.throw();
});

it("Double field accepts Infinity", async () => {
const DoubleSchema = {
name: "DoubleSchema",
properties: {
id: "int",
number: "double",
},
primaryKey: "id",
};

const realm = await Realm.open({
inMemory: true,
schema: [DoubleSchema],
});

const obj = realm.write(() => {
return realm.create(DoubleSchema.name, {
id: 1,
number: Infinity,
});
});

expect(obj.number).equals(Infinity);
});
});
});