From a1e73febc11ae57798afe2207bfeaec1d5dec250 Mon Sep 17 00:00:00 2001 From: michael-overall Date: Wed, 19 Sep 2018 23:46:48 -0400 Subject: [PATCH] fix issue#392-- add test for promises.rename() to rename existing file --- tests/spec/fs.rename.spec.js | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/spec/fs.rename.spec.js b/tests/spec/fs.rename.spec.js index 51959c2..4940c9d 100644 --- a/tests/spec/fs.rename.spec.js +++ b/tests/spec/fs.rename.spec.js @@ -151,4 +151,44 @@ describe('fs.rename', function() { }); }); }); + + it('(promise version) should rename an existing file', function(done) { + var complete1 = false; + var complete2 = false; + var fs = util.fs(); + + function maybeDone() { + if(complete1 && complete2) { + done(); + } + } + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.promises.rename('/myfile', '/myotherfile').then( + function(){ + fs.stat('/myfile', function(error, result) { + expect(error).to.exist; + expect(result).not.to.exist; + complete1 = true; + maybeDone(); + }); + + fs.stat('/myotherfile', function(error, result) { + expect(error).not.to.exist; + expect(result.nlinks).to.equal(1); + complete2 = true; + maybeDone(); + }); + }, + function(error){throw error;} + ); + + }); + }); + }); });