#387 Added unit test for writing data using the Promise API
This commit is contained in:
parent
fd3de6be2c
commit
ad42a0d6ba
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -59,4 +59,28 @@ describe('fs.write', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should write data to a file using the Promise API', function(done) {
|
||||
var fs = util.fs().promises;
|
||||
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
fs.open('/myfile', 'w+')
|
||||
.then((fd) => {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0)
|
||||
.then((result) => {
|
||||
expect(result).to.equal(buffer.length);
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
fs.stat('/myfile')
|
||||
.then((result) => {
|
||||
expect(result.type).to.equal('FILE');
|
||||
expect(result.size).to.equal(buffer.length);
|
||||
});
|
||||
})
|
||||
.catch(function(error) {
|
||||
if(error) throw error;
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue