Skip to content

Commit

Permalink
Throw error if item content is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantcornholio authored and tschaub committed Oct 13, 2017
1 parent 3704cc4 commit 3759ed6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/filesystem.js
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions test/lib/filesystem.spec.js
Expand Up @@ -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
}
}
});
});
});
});

0 comments on commit 3759ed6

Please sign in to comment.