Fix Issue #400 - add test for passing file to fs.promise.readdir() (#409)

* Fix Issue #400 - add test for passing file to fs.promise.readdir()

This adds a test to ensure that `fs.promise.readdir()` throws an error when passing in a file.

* Made changes to `fsPromises.readdir` to be more promise-friendly
This commit is contained in:
Jeffrey Espiritu 2018-10-09 13:04:19 -04:00 committed by David Humphrey
parent e77361107e
commit 7e27c8be2c
1 changed files with 21 additions and 0 deletions

View File

@ -55,3 +55,24 @@ describe('fs.readdir', function() {
}); });
}); });
}); });
/**
* fsPromises tests
*/
describe('fsPromises.readdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should return an error if the path is a file', function() {
var fsPromises = util.fs().promises;
return fsPromises.open('/myfile', 'w')
.then(fd => fsPromises.close(fd))
.then(() => fsPromises.readdir('/myfile'))
.catch(error => {
expect(error).to.exist;
expect(error.code).to.equal('ENOTDIR');
});
});
});