Skip to content

Commit

Permalink
[js] Changed io.exists() to return a rejected promise if the input va…
Browse files Browse the repository at this point in the history
…lue is not

a string. This would have caught the bad test from #1827
  • Loading branch information
jleyba committed Mar 17, 2016
1 parent 165d812 commit f59af56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## v2.53.2

* Changed `io.exists()` to return a rejected promise if the input path is not
a string
* Deprecated `Promise#thenFinally()` - use `Promise#finally()`. The thenFinally
shim added to the promise module in v2.53.0 will be removed in v3.0
Sorry for the churn!
Expand Down
6 changes: 5 additions & 1 deletion javascript/node/selenium-webdriver/io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ exports.copyDir = function(src, dst, opt_exclude) {
* @return {!Promise<boolean>} A promise for whether the file exists.
*/
exports.exists = function(aPath) {
return new Promise(function(fulfill) {
return new Promise(function(fulfill, reject) {
let type = typeof aPath;
if (type !== 'string') {
reject(TypeError(`expected string path, but got ${type}`));
}
fs.exists(aPath, fulfill);
});
};
Expand Down
6 changes: 6 additions & 0 deletions javascript/node/selenium-webdriver/test/io_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ describe('io', function() {
});
});

it('returns a rejected promise if input value is invalid', function() {
return io.exists(undefined).then(
() => assert.fail('should have failed'),
e => assert.ok(e instanceof TypeError));
});

it('works for directories', function() {
return io.exists(dir).then(assert.ok);
});
Expand Down

0 comments on commit f59af56

Please sign in to comment.