diff --git a/lib/filesystem.js b/lib/filesystem.js index dc90c063..7f2b5c78 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -138,12 +138,14 @@ function populate(directory, name, obj) { } else if (typeof obj === 'function') { // item factory item = obj(); - } else { + } else if (typeof obj === 'object') { // directory with more to populate item = new Directory(); for (var key in obj) { populate(item, key, obj[key]); } + } else { + throw new Error('Unsupported type: ' + typeof obj + ' of item ' + name); } /** * Special exception for redundant adding of empty directories. diff --git a/test/lib/filesystem.spec.js b/test/lib/filesystem.spec.js index 1cabd9f3..e6d4ac8b 100644 --- a/test/lib/filesystem.spec.js +++ b/test/lib/filesystem.spec.js @@ -311,4 +311,26 @@ describe('FileSystem.create', function() { */ assert.equal(system.getItem('/dir-a.0/dir-b.0/symlink-c.0').links, 1); }); + + it('throws if item content is not valid type', function() { + assert.throws(function() { + FileSystem.create({ + '/dir-a.0': { + 'dir-b.0': { + 'file-c.0': undefined + } + } + }); + }); + + assert.throws(function() { + FileSystem.create({ + '/dir-a.0': { + 'dir-b.0': { + 'file-c.0': 123 + } + } + }); + }); + }); });