From e50ceacfc3daa825e111976ba4192cb93c80bfe2 Mon Sep 17 00:00:00 2001 From: popomore Date: Sun, 29 Jun 2014 23:42:27 +0800 Subject: [PATCH] throw when set path is null --- index.js | 2 ++ test/File.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 938491b..d7d5c21 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test/File.js b/test/File.js index de999bf..b25a189 100644 --- a/test/File.js +++ b/test/File.js @@ -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 @@ -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'); }); });