Ensure List and Results constructors throw exception

This was already done from native code, but needed to happen for the browser shim and be tested.
This commit is contained in:
Scott Kyle 2016-02-28 13:07:05 -08:00
parent b1f656a252
commit 236d0a5eed
4 changed files with 32 additions and 2 deletions

View File

@ -21,7 +21,11 @@
import { objectTypes } from './constants'; import { objectTypes } from './constants';
import { createList, createMethods } from './util'; import { createList, createMethods } from './util';
export class List {} export class List {
constructor() {
throw new TypeError('Illegal constructor');
}
}
// Non-mutating methods: // Non-mutating methods:
createMethods(List.prototype, objectTypes.LIST, [ createMethods(List.prototype, objectTypes.LIST, [

View File

@ -21,7 +21,11 @@
import { objectTypes } from './constants'; import { objectTypes } from './constants';
import { createList, createMethods } from './util'; import { createList, createMethods } from './util';
export class Results {} export class Results {
constructor() {
throw new TypeError('Illegal constructor');
}
}
createMethods(Results.prototype, objectTypes.RESULTS, [ createMethods(Results.prototype, objectTypes.RESULTS, [
'filtered', 'filtered',

View File

@ -31,6 +31,10 @@ module.exports = BaseTest.extend({
var obj = realm.create('PersonList', {list: []}); var obj = realm.create('PersonList', {list: []});
TestCase.assertTrue(obj.list instanceof Realm.List); TestCase.assertTrue(obj.list instanceof Realm.List);
}); });
TestCase.assertThrows(function() {
new Realm.List();
});
}, },
testListLength: function() { testListLength: function() {

View File

@ -24,6 +24,17 @@ var TestCase = require('./asserts');
var schemas = require('./schemas'); var schemas = require('./schemas');
module.exports = BaseTest.extend({ 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() { testResultsLength: function() {
var realm = new Realm({schema: [schemas.TestObject]}); var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject'); var objects = realm.objects('TestObject');
@ -35,6 +46,7 @@ module.exports = BaseTest.extend({
}); });
TestCase.assertEqual(objects.length, 1); TestCase.assertEqual(objects.length, 1);
}, },
testResultsSubscript: function() { testResultsSubscript: function() {
var realm = new Realm({schema: [schemas.PersonObject]}); var realm = new Realm({schema: [schemas.PersonObject]});
realm.write(function() { realm.write(function() {
@ -50,6 +62,7 @@ module.exports = BaseTest.extend({
TestCase.assertTrue(Object.getPrototypeOf(people[0]) === schemas.PersonObject.prototype); TestCase.assertTrue(Object.getPrototypeOf(people[0]) === schemas.PersonObject.prototype);
TestCase.assertTrue(people[0] instanceof schemas.PersonObject); TestCase.assertTrue(people[0] instanceof schemas.PersonObject);
}, },
testResultsReadonly: function() { testResultsReadonly: function() {
var realm = new Realm({schema: [schemas.TestObject]}); var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject'); var objects = realm.objects('TestObject');
@ -71,17 +84,20 @@ module.exports = BaseTest.extend({
objects.length = 0; objects.length = 0;
}); });
}, },
testResultsInvalidProperty: function() { testResultsInvalidProperty: function() {
var realm = new Realm({schema: [schemas.TestObject]}); var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject'); var objects = realm.objects('TestObject');
TestCase.assertEqual(undefined, objects.ablasdf); TestCase.assertEqual(undefined, objects.ablasdf);
}, },
testResultsInvalidObjectType: function() { testResultsInvalidObjectType: function() {
var realm = new Realm({schema: [schemas.TestObject]}); var realm = new Realm({schema: [schemas.TestObject]});
TestCase.assertThrows(function() { TestCase.assertThrows(function() {
var objects = realm.objects('NotTestObject'); var objects = realm.objects('NotTestObject');
}); });
}, },
testResultsEnumerate: function() { testResultsEnumerate: function() {
var realm = new Realm({schema: [schemas.TestObject]}); var realm = new Realm({schema: [schemas.TestObject]});
var objects = realm.objects('TestObject'); var objects = realm.objects('TestObject');
@ -105,6 +121,7 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(count, 1); TestCase.assertEqual(count, 1);
TestCase.assertEqual(keys.length, 1); TestCase.assertEqual(keys.length, 1);
}, },
testResultsFiltered: function() { testResultsFiltered: function() {
var realm = new Realm({schema: [schemas.PersonObject, schemas.DefaultValues, schemas.TestObject]}); var realm = new Realm({schema: [schemas.PersonObject, schemas.DefaultValues, schemas.TestObject]});
realm.write(function() { realm.write(function() {
@ -149,6 +166,7 @@ module.exports = BaseTest.extend({
realm.objects('PersonObject').filtered("invalidQuery"); realm.objects('PersonObject').filtered("invalidQuery");
}); });
}, },
testResultsSorted: function() { testResultsSorted: function() {
var realm = new Realm({schema: [schemas.IntPrimary]}); var realm = new Realm({schema: [schemas.IntPrimary]});
var objects = realm.objects('IntPrimaryObject'); var objects = realm.objects('IntPrimaryObject');