Skip to content
This repository was archived by the owner on Dec 19, 2022. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion lib/matchers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = factory({
match: function(path, value) {
var errors = [];
var key;
if (value == null || typeof value !== 'object') {
if (value == null || typeof value !== 'object' || value instanceof Array) {
return [{path: path, value: value, message: 'should be an object'}];
}
for (key in this.fields) {
Expand Down
15 changes: 14 additions & 1 deletion test/matchers/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ describe('object matcher', function() {
}]);
});

it('rejects anything that isnt an object', function() {
it('rejects array values', function() {
var schema = new object({
name: new string(),
age: new number()
});

schema.match('path.to.something', [1,2,3]).should.eql([{
path: 'path.to.something',
value: [1,2,3],
message: 'should be an object'
}]);
});

it('rejects anything that isnt an object', function() {
var schema = new object({
name: new string(),
age: new number()
Expand Down