Add test cases for fs.appendFile with explicit encoding and flag options

This commit is contained in:
Muchtar Salimov 2018-09-24 16:16:50 -04:00
parent e3a1187ef9
commit db11f591f9
1 changed files with 32 additions and 0 deletions

View File

@ -50,6 +50,38 @@ describe('fs.appendFile', function() {
}); });
}); });
it('should append without error when explcitly entering encoding and flag options (default values)' , function(done) {
var fs = util.fs();
var contents = 'This is a file.';
var more = ' Appended.';
fs.appendFile('/myfile', more , {encoding: 'utf8', flag: 'a'}, function(error) {
if(error) throw error;
fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
it('should append without error when specfifying flag option (default value)' , function(done) {
var fs = util.fs();
var contents = 'This is a file.';
var more = ' Appended.';
fs.appendFile('/myfile', more , {flag: 'a'}, function(error) {
if(error) throw error;
fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
expect(error).not.to.exist;
expect(data).to.equal(contents + more);
done();
});
});
});
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) { it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
var fs = util.fs(); var fs = util.fs();
var contents = 'This is a file.'; var contents = 'This is a file.';