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

"Realm is not defined" when iterating through Realm Sets using Jest #3788

Closed
sync-by-unito bot opened this issue Jun 7, 2021 · 1 comment · Fixed by #3843
Closed

"Realm is not defined" when iterating through Realm Sets using Jest #3788

sync-by-unito bot opened this issue Jun 7, 2021 · 1 comment · Fixed by #3843
Assignees

Comments

@sync-by-unito
Copy link

sync-by-unito bot commented Jun 7, 2021

I'm getting the error: "ReferenceError: Realm is not defined" when attempting to iterate through a Realm set using Jest.

Realm version: 10.5.0-beta.2 (although I've tested on 10.5.0-beta.1 as well)

Sample unit test:

test("should work with the Set data type", async () => {
    const characterSchema = {
      name: "Character",
      primaryKey: "_id",
      properties: {
        _id: "objectId",
        name: "string",
        levelsCompleted: "int<>",
        inventory: "string<>",
      },
    };
    const realm = await Realm.open({
      schema: [characterSchema],
    });

    let link, hunter;
    realm.write(() => {
      link = realm.create("Character", {
        _id: new BSON.ObjectId(),
        name: "Link",
        inventory: ["elixir", "compass", "glowing shield"],
        levelsCompleted: [4, 9],
      });
      hunter = realm.create("Character", {
        _id: new BSON.ObjectId(),
        name: "Hunter",
        inventory: ["estus flask", "gloves", "rune"],
        levelsCompleted: [1, 2, 5, 24],
      });
    });
    
    hunter.inventory.forEach((inventoryItem) => {
      console.log("The hunter has an inventory item:", inventoryItem);
    });

    realm.write(() => {
      realm.delete(link);
      realm.delete(hunter);
    });
    // close the realm
    realm.close();
  });

Some notes:

  • Switching from a forEach loop to an alternative iterator method will still result in the error.
  • If you comment out the forEach method in the jest test you will not get the Realm undefined error.
  • If this code (minus the jest specific stuff) is run outside of a jest suite, for instance in a js file, it runs fine without error.
@sync-by-unito
Copy link
Author

sync-by-unito bot commented Jul 9, 2021

➤ Franck Franck commented:

This issue seems related to #1255, and possibly a type resolution error with Dict under React Native.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant