From 1d4bb7c2ad68032ad327733fd698b1b4a899fc2c Mon Sep 17 00:00:00 2001 From: Kristian Dupont Date: Wed, 7 Dec 2016 15:28:28 +0100 Subject: [PATCH] Add more tests and fix add_notification --- src/js_realm.hpp | 3 +++ tests/js/realm-tests.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index ad68b0f9..d4975f99 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -638,6 +638,9 @@ void RealmClass::add_listener(ContextType ctx, ObjectType this_object, size_t auto callback = Value::validated_to_function(ctx, arguments[1]); SharedRealm realm = *get_internal>(this_object); + if (realm->is_closed()) { + throw ClosedRealmException(); + } get_delegate(realm.get())->add_notification(callback); } diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index 0f6a2be6..8b82bf53 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -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() {