Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "realm in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'realm' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

return Realm.Sync.User.login('http://127.0.0.1:9080', credentials).then(user => {
            let config = {
                sync: {
                    user: user,
                    url: 'realm://127.0.0.1:9080/~/default',
                    fullSynchronization: true, // <---- calling subscribe should fail
                    error: (session, error) => console.log(error)
                },
                schema: [{ name: 'Dog', properties: { name: 'string' } }]
            };

            Realm.deleteFile(config);
            const realm = new Realm(config);
            TestCase.assertEqual(realm.objects('Dog').length, 0);
            TestCase.assertThrows(() => realm.objects('Dog').filtered("name == 'Lassy 1'").subscribe());
            realm.close();
        });
    },
assert.equal(Realm.name, "Realm");
  });

  /*
  it("fails", (done) => {
    assert(false);
  });
  */
});

// Almost a copy-paste from the ../spec/unit_tests.js - so it might be possible to generalize.

// Setting the timeout to the same as the ../../spec/unit_tests.js
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

Realm.copyBundledRealmFiles = function() {
  const sourceDir = path.join(__dirname, '../data');
  const destinationDir = path.dirname(Realm.defaultPath);

  for (let filename of fs.readdirSync(sourceDir)) {
    let src = path.join(sourceDir, filename);
    let dest = path.join(destinationDir, filename);

    // If the destination file already exists, then don't overwrite it.
    try {
        fs.accessSync(dest);
        continue;
    } catch (e) {}

    fs.writeFileSync(dest, fs.readFileSync(src));
  }
};
RealmLogging.patch(Realm);

const RealmTests = require('../js');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
let isDebuggerAttached = typeof v8debug === 'object';
if (!isDebuggerAttached && isNodeProccess) {
    isDebuggerAttached = /--debug|--inspect/.test(process.execArgv.join(' '));
}

if (isDebuggerAttached) {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000000;
}

// Create this method with appropriate implementation for Node testing.
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
testLogout() {
    return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.anonymous()).then((user) => {
      assertIsUser(user);

      assertIsSameUser(user, Realm.Sync.User.current);
      user.logout();

      // Is now logged out.
      TestCase.assertUndefined(Realm.Sync.User.current);

      // Can we open a realm with the registered user?
      TestCase.assertThrows(() => new Realm({sync: {user: user, url: 'realm://127.0.0.1:9080/~/test'}}));
    });
  },
// FIXME: Permission tests currently fail in react native
        TESTS.PermissionTests = require('./permission-tests');
        node_require('./adapter-tests');
        node_require('./notifier-tests');
    }
}

// If on node, run the async tests
if (isNodeProcess && process.platform !== 'win32') {
    TESTS.AsyncTests = node_require('./async-tests');
}

if (global.enableSyncTests) {
    // Ensure that the sync manager is initialized as initializing it
    // after calling clearTestState() doesn't work
    Realm.Sync.User.all;
}

var SPECIAL_METHODS = {
    beforeEach: true,
    afterEach: true,
};

exports.getTestNames = function () {
    var testNames = {};

    for (var suiteName in TESTS) {
        var testSuite = TESTS[suiteName];

        testNames[suiteName] = Object.keys(testSuite).filter(function (testName) {
            return !(testName in SPECIAL_METHODS) && typeof testSuite[testName] == 'function';
        });
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
// invalid migration function
        TestCase.assertThrows(function() {
            new Realm({schema: [], schemaVersion: 2, migration: 'invalid'});
        });

        // migration function exceptions should propogate
        var exception = new Error('expected exception');
        realm = undefined;
        TestCase.assertThrowsException(function() {
            realm = new Realm({schema: [], schemaVersion: 3, migration: function() {
                throw exception;
            }});
        }, exception);
        TestCase.assertEqual(realm, undefined);
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 1);

        // migration function shouldn't run if nothing changes
        realm = new Realm({schema: [Schemas.TestObject], migration: migrationFunction, schemaVersion: 1});
        TestCase.assertEqual(1, count);
        realm.close();

        // migration function should run if only schemaVersion changes
        realm = new Realm({schema: [Schemas.TestObject], migration: function() { count++; }, schemaVersion: 2});
        TestCase.assertEqual(2, count);
        realm.close();
    },
testRealmExists: function() {

        // Local Realms
        let config = {schema: [schemas.TestObject]};
        TestCase.assertFalse(Realm.exists(config));
        new Realm(config).close();
        TestCase.assertTrue(Realm.exists(config));

        // Sync Realms
        if (!global.enableSyncTests) {
            return;
        }
        return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.nickname("admin", true))
            .then(user => {
                const fullSyncConfig = user.createConfiguration({
                    schema: [schemas.TestObject],
                    sync: {
                        url: `realm://127.0.0.1:9080/testRealmExists_${Utils.uuid()}`,
                        fullSynchronization: true,
                    },
                });
                TestCase.assertFalse(Realm.exists(fullSyncConfig));
                new Realm(fullSyncConfig).close();
testRealmExists: function() {

        // Local Realms
        let config = {schema: [schemas.TestObject]};
        TestCase.assertFalse(Realm.exists(config));
        new Realm(config).close();
        TestCase.assertTrue(Realm.exists(config));

        // Sync Realms
        if (!global.enableSyncTests) {
            return;
        }
        return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.nickname("admin", true))
            .then(user => {
                const fullSyncConfig = user.createConfiguration({
                    schema: [schemas.TestObject],
                    sync: {
                        url: `realm://127.0.0.1:9080/testRealmExists_${Utils.uuid()}`,
                        fullSynchronization: true,
                    },
                });
// Full sync shouldn't include the permission schema
            config = {
                schema: [],
                sync: {
                    user: user,
                    url: `realm://NO_SERVER/foo`,
                    fullSynchronization: true
                }
            };
            realm = new Realm(config);
            TestCase.assertTrue(realm.empty);
            TestCase.assertEqual(realm.schema.length, 0);

            realm.close();
            Realm.deleteFile(config);
        });
    },

Is your System Free of Underlying Vulnerabilities?
Find Out Now