Fix apple-theme jest test on macOS
lyzhan7 opened this issue · 4 comments
Platform
- iOS
- macOS
- win32
- windows
- android
Describe the feature that you would like added
The apple-theme jest tests have been running on iOS, even though they are testing macOS-specific methods. After trying to change the apple-theme jest tests to run on macOS instead, the tests start failing due to this issue:
Spent several hours trying to figure out why this error was coming up only in the tests (running the code in the tester works fine). My best guess was that maybe AccessibiltyInfo/IsHighContrastEnabled needs to be mocked out, but wasn't able to figure out how to stop the error.
In order to get a separate PR unblocked, temporarily commented out the test but we should figure out how to get this error to stop showing up on macOS and get the test working again.
What component or utility would this be added to
No response
Have you discussed this feature with our team, and if so, who
No response
Additional context/screenshots
No response
Might need a mock - a lot of RN module functionality tends to need to get mocked out. esp if it accesses native info
Think I found a fix for this, which was to make sure the AccessibilityInfo module was not getting mocked out. My working understanding of why this fixed the issue is that the AccessibilityInfo module was getting mocked out automatically (I think because it's a node module, and node modules get mocked out automatically) - but it was getting mocked out incorrectly. When I would try printing out what was in AccessibilityInfo this is what I would get:
{
addEventListener: [Function: mockConstructor] {
_isMockFunction: true,
getMockImplementation: [Function (anonymous)],
mock: [Getter/Setter],
mockClear: [Function (anonymous)],
mockReset: [Function (anonymous)],
mockRestore: [Function (anonymous)],
mockReturnValueOnce: [Function (anonymous)],
mockResolvedValueOnce: [Function (anonymous)],
mockRejectedValueOnce: [Function (anonymous)],
mockReturnValue: [Function (anonymous)],
mockResolvedValue: [Function (anonymous)],
mockRejectedValue: [Function (anonymous)],
mockImplementationOnce: [Function (anonymous)],
mockImplementation: [Function (anonymous)],
mockReturnThis: [Function (anonymous)],
mockName: [Function (anonymous)],
getMockName: [Function (anonymous)]
},
announceForAccessibility: [Function: mockConstructor] {
_isMockFunction: true,
getMockImplementation: [Function (anonymous)],
mock: [Getter/Setter],
mockClear: [Function (anonymous)],
mockReset: [Function (anonymous)],
mockRestore: [Function (anonymous)],
mockReturnValueOnce: [Function (anonymous)],
mockResolvedValueOnce: [Function (anonymous)],
mockRejectedValueOnce: [Function (anonymous)],
mockReturnValue: [Function (anonymous)],
mockResolvedValue: [Function (anonymous)],
mockRejectedValue: [Function (anonymous)],
mockImplementationOnce: [Function (anonymous)],
mockImplementation: [Function (anonymous)],
mockReturnThis: [Function (anonymous)],
mockName: [Function (anonymous)],
getMockName: [Function (anonymous)]
},
...
It would print a bunch of mocked methods, but not isHighContrast. The list of methods printed out corresponded with the react-native AccessiibilityInfo object (which doesn't include isHighContastEnabled), not the react-native-macos AccessibilityInfo object.
If i printed out AccessibilityInfo while I was running the tester, all the react-native-macos methods would get printed out correctly.
I don't know why AccessibilityInfo was getting mocked out incorrectly, but using the actual module worked.