-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RNW 0.66.1: A warning is emitted if AppTheme is used at runtime and jest unittests fail. #8887
Comments
spoke to @NickGerleman, he'll take a look.
|
@nichamp I noticed you mentioned running against Android/iOS platform. Just wanted to give an FYI that we have some tools to make Jest do the right thing for out of tree platforms, at https://github.com/microsoft/rnx-kit/tree/main/packages/jest-preset. This will cause jest to include the right files per-platform, and allows you to specify platform as a command line option. Need to look at #1. Unsure what would be causing the warning until I debug it or see if there were any upstream changes. Re #2, as Alex quoted above, I think the right architecture here is for RNW to set up its mocks in a Jest preset we export, like is done for react-native itself. This wasn't something we documented though, so I think it would be righteous for me to restore behavior of being able to use AppTheme without an RNW Jest preset in the meantime, so we can be intentional about changing any sort of requirements. |
For (1) there are actually two warnings actually (I had only noticed the first at the time I created the issue): For (2), I am currently using a workaround where my tests inject a mock of NativeModules.RTCAppTheme so they are unblocked in the interim. It definitely would be helpful if the number of breaking changes between releases was minimized but I think authors' code and tests would be broken here by RN's change to how the subscriptions work too. |
Fixes microsoft#8887 Fixes warnings emitted due to upstream NativeEventEmitter refactoring, along with a more specific typing for the API to add a listener. Fix an uninetional behavior change when AppTheme is imported in a jest environment. Not manually validated yet due to some local issues.
* Fix AppTheme Regressions Fixes #8887 Fixes warnings emitted due to upstream NativeEventEmitter refactoring, along with a more specific typing for the API to add a listener. Fix an uninetional behavior change when AppTheme is imported in a jest environment. Not manually validated yet due to some local issues. * Change files
* Fix AppTheme Regressions Fixes microsoft#8887 Fixes warnings emitted due to upstream NativeEventEmitter refactoring, along with a more specific typing for the API to add a listener. Fix an uninetional behavior change when AppTheme is imported in a jest environment. Not manually validated yet due to some local issues. * Change files
* Fix AppTheme Regressions Fixes #8887 Fixes warnings emitted due to upstream NativeEventEmitter refactoring, along with a more specific typing for the API to add a listener. Fix an uninetional behavior change when AppTheme is imported in a jest environment. Not manually validated yet due to some local issues. * Change files
Resolved in 0.66.2 releasing Monday morning. |
Problem Description
Issue 1
If there is a reference to
AppTheme
, a yellow-box warning for'new NativeEventEmitter()' was called with a non-null argument without the required 'removeListeners' method
appears within the app and in console logs. It seems that RNW's implementation ofNativeModules.RTCAppTheme
does not meet the expectations of NativeEventEmitter. I speculate this is related to the event listener changes in RN and/or with #8277Issue 2
If one makes references to AppTheme in jest unittests with the default react native jest presets then it assumes assumes the platform is
ios
and at runtime it will fail an assertion with'
new NativeEventEmitter()requires a non-null argument.'
. If one changes the platform toandroid
it will emit warnings later instead, but either way AppTheme will not function correctly unless NativeModules.RTCAppTheme is mocked/shimmed before AppTheme is referenced. Perhaps this is now the expected behavior, but it has caused problems migrating from 0.64 to 0.66 for existing tests.Steps To Reproduce
Issue 1
AppTheme.isHighContrast
yarn start
with metro will repor) and observe the yellow box warningIssue 2
ios
.'
new NativeEventEmitter()requires a non-null argument.'
. If one changes the platform toandroid
it will emit warnings later instead.Expected Results
Issue 1
No warnings should be omitted. RNW's built-in native module should follow the expectations of RN where possible.
Issue 2
There should be a built-in mock for the native module so that AppTheme can be safely referenced in jest unittests without the developer needing hacks like assigning to NativeModules.RTCAppTheme directly.
CLI version
6.1.0
Environment
Target Platform Version
10.0.19041
Target Device(s)
Desktop
Visual Studio Version
Visual Studio 2019
Build Configuration
Debug
Snack, code example, screenshot, or link to a repository
No response
The text was updated successfully, but these errors were encountered: