Skip to content

Commit

Permalink
Fix #1517
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed May 24, 2019
1 parent 4c3bfeb commit e182a17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/promise.js
Expand Up @@ -102,6 +102,11 @@ Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
}
catchInstances.length = j;
fn = arguments[i];

if (typeof fn !== "function") {
throw new TypeError("The last argument to .catch() " +
"must be a function, got " + util.toString(fn));
}
return this.then(undefined, catchFilter(catchInstances, fn, this));
}
return this.then(undefined, fn);
Expand Down
14 changes: 14 additions & 0 deletions test/mocha/catch_filter.js
Expand Up @@ -288,6 +288,20 @@ describe("A promise handler that is caught in a filter", function() {
});

});

specify("should throw type error for not passing function", function() {
try {
var a = Promise.reject(new Error("asd"));
a.caught(Promise.TypeError, "string");
throw new Error("fail");
} catch (e) {
if (e instanceof Promise.TypeError) {
return true;
} else {
throw new Error("fail");
}
}
});
});

describe("A promise handler with a predicate filter", function() {
Expand Down

0 comments on commit e182a17

Please sign in to comment.