Add more tests and fix add_notification

This commit is contained in:
Kristian Dupont 2016-12-07 15:28:28 +01:00 committed by Ari Lazier
parent bf85c285a0
commit 1d4bb7c2ad
2 changed files with 27 additions and 0 deletions

View File

@ -638,6 +638,9 @@ void RealmClass<T>::add_listener(ContextType ctx, ObjectType this_object, size_t
auto callback = Value::validated_to_function(ctx, arguments[1]);
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
if (realm->is_closed()) {
throw ClosedRealmException();
}
get_delegate<T>(realm.get())->add_notification(callback);
}

View File

@ -657,6 +657,8 @@ module.exports = {
var person = realm.objects('PersonObject')[0];
// The tests below assert that everthing throws when
// operating on a closed realm
realm.close();
TestCase.assertThrows(function() {
@ -666,6 +668,28 @@ module.exports = {
TestCase.assertThrows(function() {
realm.objects('PersonObject');
});
TestCase.assertThrows(function() {
realm.addListener('change', () => {});
});
TestCase.assertThrows(function() {
realm.create('PersonObject', {name: 'Ari', age: 10});
});
TestCase.assertThrows(function() {
realm.delete(person);
});
TestCase.assertThrows(function() {
realm.deleteAll();
});
TestCase.assertThrows(function() {
realm.write(() => {});
});
},
testRealmObjectForPrimaryKey: function() {