diff --git a/tests/js/linkingobjects-tests.js b/tests/js/linkingobjects-tests.js index 252be90ee0..7d5692efca 100644 --- a/tests/js/linkingobjects-tests.js +++ b/tests/js/linkingobjects-tests.js @@ -219,5 +219,24 @@ module.exports = { }); TestCase.assertEqual(olivier.linkingObjectsCount(), 2); + }, + + testInfinityRecursion: function() { + var realm = new Realm({schema: [schemas.Dog, schemas.Person]}); + + realm.write(() => { + realm.create('Person', { + name: "test", + dog: realm.create('Dog', { + name: 'harry' + }) + }); + }); + + const persons = realm.objects('Person'); + + const json = JSON.stringify(persons.slice()); + + TestCase.assertType(json, 'string'); } }; diff --git a/tests/js/schemas.js b/tests/js/schemas.js index 44b69e5b24..4b39f69e67 100644 --- a/tests/js/schemas.js +++ b/tests/js/schemas.js @@ -324,3 +324,20 @@ exports.Country = { } }; + + +exports.Dog = { + name: 'Dog', + properties: { + name: 'string', + owners: {type: 'linkingObjects', objectType: 'Person', property: 'dog'}, + } +}; + +exports.Person = { + name: 'Person', + properties: { + name: 'string', + dog: 'Dog', + } +};