diff --git a/lib/browser/lists.js b/lib/browser/lists.js index 1e95ca80..d4b8627a 100644 --- a/lib/browser/lists.js +++ b/lib/browser/lists.js @@ -21,7 +21,11 @@ import { objectTypes } from './constants'; import { createList, createMethods } from './util'; -export class List {} +export class List { + constructor() { + throw new TypeError('Illegal constructor'); + } +} // Non-mutating methods: createMethods(List.prototype, objectTypes.LIST, [ diff --git a/lib/browser/results.js b/lib/browser/results.js index 2cedcb97..dba15d08 100644 --- a/lib/browser/results.js +++ b/lib/browser/results.js @@ -21,7 +21,11 @@ import { objectTypes } from './constants'; import { createList, createMethods } from './util'; -export class Results {} +export class Results { + constructor() { + throw new TypeError('Illegal constructor'); + } +} createMethods(Results.prototype, objectTypes.RESULTS, [ 'filtered', diff --git a/tests/js/list-tests.js b/tests/js/list-tests.js index 37f8f4a5..2441486d 100644 --- a/tests/js/list-tests.js +++ b/tests/js/list-tests.js @@ -31,6 +31,10 @@ module.exports = BaseTest.extend({ var obj = realm.create('PersonList', {list: []}); TestCase.assertTrue(obj.list instanceof Realm.List); }); + + TestCase.assertThrows(function() { + new Realm.List(); + }); }, testListLength: function() { diff --git a/tests/js/results-tests.js b/tests/js/results-tests.js index 02a80448..571a5447 100644 --- a/tests/js/results-tests.js +++ b/tests/js/results-tests.js @@ -24,6 +24,17 @@ var TestCase = require('./asserts'); var schemas = require('./schemas'); module.exports = BaseTest.extend({ + testResultsConstructor: function() { + var realm = new Realm({schema: [schemas.TestObject]}); + var objects = realm.objects('TestObject'); + + TestCase.assertTrue(objects instanceof Realm.Results); + + TestCase.assertThrows(function() { + new Realm.Results(); + }); + }, + testResultsLength: function() { var realm = new Realm({schema: [schemas.TestObject]}); var objects = realm.objects('TestObject'); @@ -35,6 +46,7 @@ module.exports = BaseTest.extend({ }); TestCase.assertEqual(objects.length, 1); }, + testResultsSubscript: function() { var realm = new Realm({schema: [schemas.PersonObject]}); realm.write(function() { @@ -50,6 +62,7 @@ module.exports = BaseTest.extend({ TestCase.assertTrue(Object.getPrototypeOf(people[0]) === schemas.PersonObject.prototype); TestCase.assertTrue(people[0] instanceof schemas.PersonObject); }, + testResultsReadonly: function() { var realm = new Realm({schema: [schemas.TestObject]}); var objects = realm.objects('TestObject'); @@ -71,17 +84,20 @@ module.exports = BaseTest.extend({ objects.length = 0; }); }, + testResultsInvalidProperty: function() { var realm = new Realm({schema: [schemas.TestObject]}); var objects = realm.objects('TestObject'); TestCase.assertEqual(undefined, objects.ablasdf); }, + testResultsInvalidObjectType: function() { var realm = new Realm({schema: [schemas.TestObject]}); TestCase.assertThrows(function() { var objects = realm.objects('NotTestObject'); }); }, + testResultsEnumerate: function() { var realm = new Realm({schema: [schemas.TestObject]}); var objects = realm.objects('TestObject'); @@ -105,6 +121,7 @@ module.exports = BaseTest.extend({ TestCase.assertEqual(count, 1); TestCase.assertEqual(keys.length, 1); }, + testResultsFiltered: function() { var realm = new Realm({schema: [schemas.PersonObject, schemas.DefaultValues, schemas.TestObject]}); realm.write(function() { @@ -149,6 +166,7 @@ module.exports = BaseTest.extend({ realm.objects('PersonObject').filtered("invalidQuery"); }); }, + testResultsSorted: function() { var realm = new Realm({schema: [schemas.IntPrimary]}); var objects = realm.objects('IntPrimaryObject');