Skip to content

Commit

Permalink
Change Promise detection code in jest-circus to support non-global Pr…
Browse files Browse the repository at this point in the history
…omise implementations (#4375)

* Change Promise detection code in jest-circus to support non-global Promise implementations

To provide better interop for Promise libraries such as bluebird and Q, this changes
the part of jest-circus that detects a returned Promise from a test or hook to only
check that the value is an object with a then method on it, rather than checking that
the value is instanceof Promise. This is considered the standard way of checking for
a Promises/A+-compliant Promise. As an added bonus, this check works cross-realm.

* Update utils.js
  • Loading branch information
suchipi authored and cpojer committed Aug 27, 2017
1 parent e535665 commit a3ed980
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/jest-circus/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,13 @@ const callAsyncFn = (
return reject(error);
}

// If it's a Promise, return it.
if (returnedValue instanceof Promise) {
// If it's a Promise, return it. Test for an object with a `then` function
// to support custom Promise implementations.
if (
typeof returnedValue === 'object' &&
returnedValue !== null &&
typeof returnedValue.then === 'function'
) {
return returnedValue.then(resolve, reject);
}

Expand Down

0 comments on commit a3ed980

Please sign in to comment.