Skip to content

Commit

Permalink
throw when set path is null
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Jun 29, 2014
1 parent 7c71bf3 commit e50ceac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Object.defineProperty(File.prototype, 'path', {
return this.history[this.history.length - 1];
},
set: function(path) {
if (typeof path !== 'string') throw new Error('path should be string');

// record history only when path changed
if (path && path !== this.path) {
this.history.push(path);
Expand Down
12 changes: 9 additions & 3 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,14 @@ describe('File', function() {
file.path = '/test/test.coffee';
file.path.should.eql('/test/test.coffee');
file.history.should.eql(['/test/test.coffee']);

// ignore when set empty string
file.path = '';
file.path.should.eql('/test/test.coffee');
file.history.should.eql(['/test/test.coffee']);
});

it('should not record history when path is null', function() {
it('should throw when set path null', function() {
var file = new File({
cwd: '/',
path: null
Expand All @@ -585,8 +590,9 @@ describe('File', function() {
should.not.exist(file.path)
file.history.should.eql([]);

file.path = '/test/test.coffee';
file.path.should.eql('/test/test.coffee');
(function() {
file.path = null;
}).should.throw('path should be string');
});
});

Expand Down

0 comments on commit e50ceac

Please sign in to comment.