Skip to content

AccessibilityInfo: added missing tests for Promise based methods, align null checks and error message code style #56150

Closed
chicio wants to merge 15 commits into
react:mainfrom
chicio:accessibility_missing_tests
Closed

AccessibilityInfo: added missing tests for Promise based methods, align null checks and error message code style #56150
chicio wants to merge 15 commits into
react:mainfrom
chicio:accessibility_missing_tests

Conversation

@chicio

@chicio chicio commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary:

This PR continue the work I'm doing to improve the AccessibilityInfo module (#56066 and connected PRs).

In this new PR I added the missing tests for all the Promise based methods in the AccessibilityInfo, to prevent regressions similar to those fixed in the previous PRs.

This PR also includes a couple of small code style consistency improvement:

  • aligned the null check in getRecommendedTimeoutMillis to the other ones already present in the file
  • aligned the error messages returned from isGrayscaleEnabled, isInvertColorsEnabled and isReduceMotionEnabled to the other ones
  • added the docs links where was missing (related to the PR I opened on the react-native doc repo)

Changelog:

[GENERAL] [ADDED] - AccessibilityInfo: added missing tests for Promise based methods, align null checks and error message code style

Test Plan:

I run the tests that I added to verify their correctness. Some of them were failing because of the change of the error messages, and I made them green by changing the message in the production code. For this others, I verified their correctness by breaking the production code to see if they were failing.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 19, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 19, 2026
@chicio

chicio commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Hi @vzaidman, maybe you can help me to import also this one? Thank you so much 🙏

@chicio

chicio commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

Hi @cortinico, can you help me with this PR? Thanks 🙏

@cortinico cortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, but left a couple of nits 👍

const isReduceMotionEnabled =
await AccessibilityInfo.isReduceMotionEnabled();

expect(isReduceMotionEnabled).toBe(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also assert this?

expect(mockGetCurrentReduceMotionState).toHaveBeenCalled()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

const nativeAccessibilityInfoModule = jest.requireMock(
'../NativeAccessibilityInfo',
);
nativeAccessibilityInfoModule.default = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from the test title: 'should throw error if isReduceMotionEnabled is not available'

You should mockNativeAccessibilityInfoAndroid.isReduceMotionEnabled = null;

instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the test is correct, but the title wrong.
I fixed it to match the naming used in similar tests that is should throw error if NativeAccessibilityInfoAndroid is not available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah either works

@chicio

chicio commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

Generally looks good to me, but left a couple of nits 👍

Thanks 🙏 I addressed all the comment. Let me know if you spot anything else or it is ready to be merged.

@meta-codesync

meta-codesync Bot commented Apr 23, 2026

Copy link
Copy Markdown

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D102190403.

@meta-codesync meta-codesync Bot closed this in 8fc503d Apr 27, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @chicio in 8fc503d

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants