Skip to content

Commit

Permalink
Avoid the use of .caught(...) on promises that we didn't necessarily …
Browse files Browse the repository at this point in the history
…create ourselves.

Fixes unexpected-promise with non-Bluebird promises (reporter by Munter via Gitter).
  • Loading branch information
papandreou committed Jun 1, 2015
1 parent d6221e3 commit fb21723
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Unexpected.js
Expand Up @@ -652,8 +652,8 @@ Unexpected.prototype.expect = function expect(subject, testDescriptionString) {
var callInNestedContext = function (callback) {
try {
var result = oathbreaker(callback());
if (result && typeof result.then === 'function' && typeof result.caught === 'function') {
return result.caught(function (e) {
if (result && typeof result.then === 'function') {
return result.then(undefined, function (e) {
if (e && e._isUnexpected) {
truncateStack(e, wrappedExpect);
throw handleNestedExpects(wrappedExpect, e, assertion);
Expand Down Expand Up @@ -793,7 +793,7 @@ Unexpected.prototype.expect = function expect(subject, testDescriptionString) {
try {
var promise = executeExpect(subject, testDescriptionString, args);
if (promise && typeof promise.then === 'function') {
return promise.caught(function (e) {
return promise.then(undefined, function (e) {
if (e && e._isUnexpected) {
// TODO truncate the stack
that.setErrorMessage(e);
Expand Down Expand Up @@ -857,7 +857,7 @@ Unexpected.prototype.async = function (cb) {
result.then(function () {
that._isAsync = false;
done();
}).caught(function (err) {
}, function (err) {
that._isAsync = false;
done(err);
});
Expand Down

0 comments on commit fb21723

Please sign in to comment.