Skip to content

Commit

Permalink
Fix(Image.resolveAssetSource) do not mock function in tests
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Delphine Bugner committed Mar 14, 2024
1 parent 47a3f52 commit f06ac66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/Image/__tests__/Image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,9 @@ describe('<Image />', () => {
expect(secondInstance).toBe(null);
expect(imageInstancesFromCallback.size).toBe(0);
});

it('should resolve asset source even when Image module is mocked', async () => {
const resolvedSource = Image.resolveAssetSource({uri: 'foo-bar.jpg'});
expect(resolvedSource).toEqual({uri: 'foo-bar.jpg'});
});
});
1 change: 0 additions & 1 deletion packages/react-native/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ jest
Image.prefetch = jest.fn();
Image.prefetchWithMetadata = jest.fn();
Image.queryCache = jest.fn();
Image.resolveAssetSource = jest.fn();

return Image;
})
Expand Down

0 comments on commit f06ac66

Please sign in to comment.