Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RJS-2143: Tests to clarify number conversion #6623

Merged
merged 3 commits into from
Apr 18, 2024
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);
});
});
});
Loading