Skip to content
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

Expo SDK 52 expo-font's isLoaded method no longer compatible with RNTL's render method, @expo/vector-icons depends on this #1712

Open
timheilman opened this issue Nov 28, 2024 · 1 comment

Comments

@timheilman
Copy link

Describe the bug

Upgrading from Expo SDK 51 to Expo SDK 52 causes expo-font's major version to move from 12 to 13. This causes a failure with the react-native-test-renderer's render method whenever expo-font's isLoaded method is called:

    TypeError: loadedNativeFonts.forEach is not a function

      3 |
      4 | export default function App() {
    > 5 |   const robotoLoaded = isLoaded("Roboto");
        |                                ^
      6 |   return (
      7 |     <View style={styles.container}>
      8 |       <Text>{robotoLoaded}</Text>

      at forEach (node_modules/expo-font/src/memory.ts:21:23)
      at isLoaded (node_modules/expo-font/src/Font.ts:27:24)
      at App (App.js:5:32)

In particular, this impacts @expo/vector-icons rendering, including in react-native-paper, which has had an issue filed in that repo.

I'm not sure whether the fix to this needs to be made in expo-fonts or in react-native-testing-library, or elsewhere, but I'm starting here.

Expected behavior

Using @expo/vector-icons, which itself calls expo-font's isLoaded method, will not cause react-native-test-renderer's render method to fail with the above exception.

Steps to Reproduce

I've made a minimal reproduction. A simple npm install then npm test will demonstrate the issue.

Screenshots

This is purely a testing issue, no screenshots.

Versions

➜  react-native-testing-library-expo-icons-issue git:(master) npx envinfo --npmPackages react,react-native,react-test-renderer,@testing-library/react-native                                 <region:us-west-2>
Need to install the following packages:
[email protected]
Ok to proceed? (y) y

  npmPackages:
    @testing-library/react-native: ^12.8.1 => 12.9.0
    react: 18.3.1 => 18.3.1
    react-native: 0.76.3 => 0.76.3
    react-test-renderer: ^18.3.1 => 18.3.1
@timheilman
Copy link
Author

Here is a workaround, from jest setup file (before env):

jest.mock("expo-font", () => {
  const module: typeof import("expo-font") = {
    ...jest.requireActual("expo-font"),
    isLoaded: jest.fn(() => true),
  };

  return module;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant