Fix/image methods mock in jest setup#43497
Closed
delphinebugner wants to merge 8 commits intofacebook:mainfrom
Closed
Fix/image methods mock in jest setup#43497delphinebugner wants to merge 8 commits intofacebook:mainfrom
delphinebugner wants to merge 8 commits intofacebook:mainfrom
Conversation
added 8 commits
March 14, 2024 22:57
It's purely a JS function, we can not mock it - I would say more, we should not mock it in test and ensure something is returned (for example react native fast image relies on this function to compute the URL of its component, without this fix, every URLs disappear in snapshots - see facebook#41957)
Contributor
|
Thanks for adding the additional tests in this PR! |
Contributor
|
@tdn120 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Context
Image.resolveAssetSourcereturns nothing in test env with the new JS mock, when some test relies on it.react-native-fast-imagewhich usesImage.resolveAssetSourceto compute URLs.This is what this PR intends to do.
Content
Along fixing the Image module mock in jest.setup, this PR :
NativeImageLoader:prefetchImageWithMetadata,getSizeWithHeaders&queryCache. After this PR, no method from NativeImageLoader remains unmocked.Changelog:
[GENERAL][FIXED] - fix jest setup for Image methods (resolveAssetSource, getSize, prefetch, queryCache)
Test Plan:
See exhaustive unit tests in PR.
You can re-use the mock with all the methods mocked and see how the new unit tests fail.
I also patched those changes on my project: my snapshot did have their URL back (see demonstrative screenshots in my original PR: #41957 - NB; fixed mock was different but result was the same -> those screenshots cover only two cases, but anyway they illustrate well the case!)