-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Promise detection code in jest-circus to support non-global Promise implementations #4375
Change Promise detection code in jest-circus to support non-global Promise implementations #4375
Conversation
…omise 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.
Codecov Report
@@ Coverage Diff @@
## master #4375 +/- ##
==========================================
- Coverage 56.2% 55.85% -0.36%
==========================================
Files 191 189 -2
Lines 6421 6383 -38
Branches 6 6
==========================================
- Hits 3609 3565 -44
- Misses 2809 2815 +6
Partials 3 3
Continue to review full report at Codecov.
|
Nice! I updated the comment a bit to not mention specific custom Promise implementations as those ones likely won't be relevant in the future. |
Do we want to add a test for this? |
Yes, if you want to add some. The old code already does this, so it's simply aligning the implementation but explicit tests are always good. |
I started writing some tests for this but ran into some weirdness around #3785. I don't want to add tests that don't pass with jasmine, but pass with circus, so I'll defer adding tests for this until circus is the only runner. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This isn't related to any particular open issue with jest-circus, but I noticed it while reading through the code to familiarize myself with it, and so decided to submit it on the side as a small improvement.
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.
Test plan
I think we should add an integration test to this that pulls in bluebird, Q, or jQuery deferred, and verifies that the test runs as expected, but I'm not sure how to add an integration test that has a dependency like that. Should it be a dev dependency of the whole project?