Skip to content

Commit

Permalink
RJS-2143: Tests to clarify number conversion (#6623)
Browse files Browse the repository at this point in the history
* Tests to clarify number conversion
  • Loading branch information
kneth authored Apr 18, 2024
1 parent 574bea3 commit 39b10a7
Showing 1 changed file with 60 additions and 0 deletions.
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);
});
});
});

0 comments on commit 39b10a7

Please sign in to comment.