-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
global.Promise
replacement in Jest setup causing problems.
#29303
Labels
Comments
Copy-pasting the error output I mention at jestjs/jest#10221 to help others find this issue:
|
chrisbobbe
added a commit
to chrisbobbe/react-native
that referenced
this issue
Aug 24, 2020
It looks like this line was introduced in 3ff3987, in 2015, and it has remained in a similar form since then. I haven't found any explanation for it. At jestjs/jest#10221 [1], a core Jest maintainer says, """ As an aside, one should never replace `global.Promise` [...]. E.g. when using `async-await` you will always get the native `Promise` regardless of the value of `global.Promise`. """ jestjs/jest#10221 is one issue this line has raised, for anyone using the latest features of Jest to test async code in their React Native projects. [1] jestjs/jest#10221 (comment) Fixes: facebook#29303
chrisbobbe
added a commit
to chrisbobbe/react-native
that referenced
this issue
Aug 25, 2020
It looks like this line was introduced in 3ff3987, in 2015, and it has remained in a similar form since then. I haven't found any explanation for it. At jestjs/jest#10221 [1], a core Jest maintainer says, """ As an aside, one should never replace `global.Promise` [...]. E.g. when using `async-await` you will always get the native `Promise` regardless of the value of `global.Promise`. """ jestjs/jest#10221 is one issue this line has raised, for anyone using the latest features of Jest to test async code in their React Native projects. [1] jestjs/jest#10221 (comment) Fixes: facebook#29303
chrisbobbe
added a commit
to chrisbobbe/react-native
that referenced
this issue
Aug 25, 2020
It looks like this line was introduced in 3ff3987, in 2015, and it has remained in a similar form since then. I haven't found any explanation for it. At jestjs/jest#10221 [1], a core Jest maintainer says, """ As an aside, one should never replace `global.Promise` [...]. E.g. when using `async-await` you will always get the native `Promise` regardless of the value of `global.Promise`. """ jestjs/jest#10221 is one issue this line has raised, for anyone using the latest features of Jest to test async code in their React Native projects. [1] jestjs/jest#10221 (comment) Fixes: facebook#29303
chrisbobbe
added a commit
to chrisbobbe/react-native
that referenced
this issue
Aug 25, 2020
It looks like this line was introduced in 3ff3987, in 2015, and it has remained in a similar form since then. I haven't found any explanation for it. At jestjs/jest#10221 [1], a core Jest maintainer says, """ As an aside, one should never replace `global.Promise` [...]. E.g. when using `async-await` you will always get the native `Promise` regardless of the value of `global.Promise`. """ jestjs/jest#10221 is one issue this line has raised, for anyone using the latest features of Jest to test async code in their React Native projects. [1] jestjs/jest#10221 (comment) Fixes: facebook#29303
chrisbobbe
added a commit
to chrisbobbe/react-native
that referenced
this issue
Aug 25, 2020
It looks like this line was introduced in 3ff3987, in 2015, and it has remained in a similar form since then. I haven't found any explanation for it. At jestjs/jest#10221 [1], a core Jest maintainer says, """ As an aside, one should never replace `global.Promise` [...]. E.g. when using `async-await` you will always get the native `Promise` regardless of the value of `global.Promise`. """ jestjs/jest#10221 is one issue this line has raised, for anyone using the latest features of Jest to test async code in their React Native projects. [1] jestjs/jest#10221 (comment) Fixes: facebook#29303
Merged
7 tasks
facebook-github-bot
pushed a commit
that referenced
this issue
Sep 12, 2022
Summary: Pull Request resolved: #34659 We've used this Promise polyfill in Jest setup since at least 2015 ([`3ff3987`](3ff3987)), when native Promise implementations were either non-existent or new and unstable. We no longer need it. It causes issues with "modern" timers in Jest, as documented in: - #29303 - jestjs/jest#10221 It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412. Changelog: [General][Changed] - Don't polyfill Promise in Jest setup Reviewed By: huntie Differential Revision: D39417597 fbshipit-source-id: d12433ed66c06a402632c2e1d525aad112ef9b0c
Fixed in #34659 |
OlimpiaZurek
pushed a commit
to OlimpiaZurek/react-native
that referenced
this issue
May 22, 2023
Summary: Pull Request resolved: facebook#34659 We've used this Promise polyfill in Jest setup since at least 2015 ([`3ff3987`](facebook@3ff3987)), when native Promise implementations were either non-existent or new and unstable. We no longer need it. It causes issues with "modern" timers in Jest, as documented in: - facebook#29303 - jestjs/jest#10221 It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412. Changelog: [General][Changed] - Don't polyfill Promise in Jest setup Reviewed By: huntie Differential Revision: D39417597 fbshipit-source-id: d12433ed66c06a402632c2e1d525aad112ef9b0c
tungdo194
pushed a commit
to tungdo194/rn-test
that referenced
this issue
Apr 28, 2024
Summary: We've used this Promise polyfill in Jest setup since at least 2015 ([`3ff3987`](facebook/react-native@3ff3987)), when native Promise implementations were either non-existent or new and unstable. We no longer need it. It causes issues with "modern" timers in Jest, as documented in: - facebook/react-native#29303 - jestjs/jest#10221 It can also obscure real issues due to its default silent handling of uncaught rejections, eg: D39418412. Changelog: [General][Changed] - Don't polyfill Promise in Jest setup Differential Revision: D39417597 fbshipit-source-id: 1773032343f914a37789c7bc43760838f2d86d31
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hi! 👋
What is the purpose of replacing the global Promise in this line of
jest/setup.js
:It looks like it was first introduced in 3ff3987 (quite a while ago) and has remained in a similar form since then. There's no explanation of this choice specifically (if I understand correctly), so I think if it must remain, it would be good to put a code comment there. 🙂
Description
'promise' refers to the NPM package with that name.
It interferes with Jest when using their new "modern" implementation of fake timers (documented here), as I describe at jestjs/jest#10221.
One interesting note on that issue, from a Jest maintainer, is this:
Might it be OK and appropriate to remove the line?
React Native version:
Steps To Reproduce
Reproduction of the issue (and more discussion) at jestjs/jest#10221.
Expected Results
React Native's Jest setup doesn't interfere with ordinary, well-documented ways of testing with Jest.
The text was updated successfully, but these errors were encountered: