From e3a285ae54ec3fc2d0baf1013418bf161a6d2fe6 Mon Sep 17 00:00:00 2001 From: Deepanjali Gerangal Date: Mon, 24 Sep 2018 16:34:36 -0400 Subject: [PATCH] fix #418 test for fsPromises.truncate(path[, len]) to test when length is negative --- tests/spec/fs.truncate.spec.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/spec/fs.truncate.spec.js b/tests/spec/fs.truncate.spec.js index 44fda48..198ab87 100644 --- a/tests/spec/fs.truncate.spec.js +++ b/tests/spec/fs.truncate.spec.js @@ -213,10 +213,10 @@ describe('fs.truncate', function() { }); }); - describe('fsPromises.truncate', function () { beforeEach(util.setup); afterEach(util.cleanup); + it('should error when path does not exist (with promises)', () => { var fsPromises = util.fs().promises; @@ -226,4 +226,16 @@ describe('fsPromises.truncate', function () { expect(error.code).to.equal('ENOENT'); }); }); -}); \ No newline at end of file + + it('should error when length is negative', () => { + var fsPromises = util.fs().promises; + var contents = 'This is a file.'; + + fsPromises.writeFile('/myfile', contents) + .then(() => fsPromises.truncate('/myfile', -1)) + .catch(error => { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + }); + }); +});