Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error if item content is invalid #218

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion lib/filesystem.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
}
});
});
});
});