Skip to content

Commit

Permalink
Merge 604678d into 13bf540
Browse files Browse the repository at this point in the history
  • Loading branch information
mrupley committed Dec 27, 2017
2 parents 13bf540 + 604678d commit d5bb77a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ class ObjectType extends Type {
throw new MyTypeError('Expected an object for properties (found: %type)', propTypes);
}

if (Array.isArray(propTypes)) {
throw new MyTypeError('Expected an object for properties (found: array)');
}

this.propTypes = propTypes;
this.propNames = Object.keys(propTypes);
this.dict = null;
Expand Down Expand Up @@ -632,6 +636,10 @@ class ObjectType extends Type {
return;
}

if(Array.isArray(value)) {
throw new MyTypeError(`Object is an array`, value);
}

// test provided properties

const propNames = Object.keys(value);
Expand Down
2 changes: 2 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test('Objects', (t) => {
// creation

t.throws(() => { object(123); });
t.throws(() => { object([]); });

// optional

Expand All @@ -63,6 +64,7 @@ test('Objects', (t) => {
// assert

t.throws(() => { schema(false, props).assert({ o: {} }); });
t.throws(() => { schema(false, props).assert({ o: {a: []} }); });

// properties

Expand Down

0 comments on commit d5bb77a

Please sign in to comment.