fix issue#392-- add test for promises.rename() to rename existing file

This commit is contained in:
michael-overall 2018-09-19 23:46:48 -04:00
parent fd3de6be2c
commit a1e73febc1
1 changed files with 40 additions and 0 deletions

View File

@ -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;}
);
});
});
});
}); });