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 { createList, createMethods } from './util';
export class List {}
export class List {
constructor() {
throw new TypeError('Illegal constructor');
}
}
// Non-mutating methods:
createMethods(List.prototype, objectTypes.LIST, [

View File

@ -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',

View File

@ -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() {

View File

@ -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');