Skip to content

Instantly share code, notes, and snippets.

@stigi
Created February 21, 2018 11:32
Show Gist options
  • Select an option

  • Save stigi/d0117b2c054fa48a960e3de538e5eac7 to your computer and use it in GitHub Desktop.

Select an option

Save stigi/d0117b2c054fa48a960e3de538e5eac7 to your computer and use it in GitHub Desktop.
import Realm from 'realm'
const openAndCloseWithModel = async (schema) => {
let realm
try {
console.log("Opening realm")
realm = await Realm.open({schema})
.catch((e) => {
console.error("Cought rejection error")
console.error(e)
})
} catch (e) {
// >>> OBSERVE BUG HERE <<<
// Expected this error to be delivered via the promise rejection
console.error("Cought thrown error")
console.error(e)
}
if (realm) {
console.log("Closing realm")
realm.close()
}
return realm
}
const runTest = async () => {
class Model {}
Model.schema = {
name: 'Model',
primaryKey: 'id',
properties: {
id: 'int',
name: 'string',
}
}
await openAndCloseWithModel([Model])
// update model schema and add `description`
Model.schema = {
name: 'Model',
primaryKey: 'id',
properties: {
id: 'int',
name: 'string',
description: 'string',
}
}
await openAndCloseWithModel([Model])
}
runTest().then(() => {
console.log("Exiting")
// importing Realm prevents the process from ending by itself
// See https://github.com/realm/realm-js/issues/1387
process.exit(0)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment