Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/core/propertyTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ registerPropertyType('vec4', {x: 0, y: 0, z: 0, w: 1}, vecParse, coordinates.str
* @param {function} [stringify=defaultStringify] - Stringify to DOM function.
*/
function registerPropertyType (type, defaultValue, parse, stringify) {
if ('type' in propertyTypes) {
error('Property type ' + type + ' is already registered.');
return;
if (type in propertyTypes) {
throw new Error('Property type ' + type + ' is already registered.');
}

propertyTypes[type] = {
Expand Down
9 changes: 9 additions & 0 deletions tests/core/propertyTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ suite('propertyTypes', function () {
assert.ok('mytype' in propertyTypes);
assert.equal(propertyTypes.mytype.default, 5);
});

test('rejects duplicate type names', function () {
assert.notOk('duplicate' in propertyTypes);
register('duplicate', 'first');
assert.equal(propertyTypes.duplicate.default, 'first');
assert.throws(function () {
register('duplicate', 'second');
}, 'Property type duplicate is already registered.');
});
});

suite('int', function () {
Expand Down
3 changes: 3 additions & 0 deletions tests/core/schema.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global assert, suite, test */
var Schema = require('core/schema');
var propertyTypes = require('core/propertyTypes').propertyTypes;
var registerPropertyType = require('core/propertyTypes').registerPropertyType;

var isSingleProperty = Schema.isSingleProperty;
Expand Down Expand Up @@ -160,6 +161,7 @@ suite('schema', function () {
});

test('sets default value if not defined', function () {
delete propertyTypes.faketype;
registerPropertyType('faketype', 'FAKEDEFAULT');
var definition = processSchema({type: 'faketype'});
assert.equal(definition.default, 'FAKEDEFAULT');
Expand All @@ -181,6 +183,7 @@ suite('schema', function () {

suite('processSchema', function () {
test('processes all property definitions', function () {
delete propertyTypes.faketype;
registerPropertyType('faketype', 'FAKEDEFAULT');

var schema = processSchema({
Expand Down