How to test asset loading, getting errors

Please provide the following:

  1. SDK Version: 45
  2. Platforms(Android/iOS/web/all): jest
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I get a variety of errors such as:

ReferenceError: You are trying to import a file after the Jest environment has been torn down. From tests/App-test.js.

Error: Module “[object Object]” is missing from the asset registry

  it(`renders the root without loading screen`, async () => {
    await act(async () => {
      console.log('pre render');
      await mockFontLoadAsyncPromise;
      await mockAssetLoadAsyncPromise;
      const el = <App skipLoadingScreen />;
      testRenderer = renderer.create(el);
      tree = testRenderer.toJSON();
      console.log('post render');
    console.log('post act');

Code under test:

export default function App(props) {
    const [isLoadingComplete, setLoadingComplete] = useState(false);
    console.log('App render, isLoadingComplete:', isLoadingComplete);

    useEffect(() => {
        async function prepare() {
            try {
                await SplashScreen.preventAutoHideAsync();
                await loadResourcesAsync();
            } catch (e) {
                console.warn('prepare err:', e);
            } finally {
                // Tell the application to render
                await SplashScreen.hideAsync();

    }, []);

    if (!isLoadingComplete && !props.skipLoadingScreen) {
        console.log('show loading screen');
        return (
    console.log('show app');
    return (
        <GlobalContext.Provider value={defaultContext}>
            <PaperProvider theme={theme}>
                <LoadedApp />

async function loadResourcesAsync() {
    return Promise.all([
            require('./assets/images/robot-dev.png'), // eslint-disable-line global-require
            require('./assets/images/robot-prod.png'), // eslint-disable-line global-require
            iconfont: require('./assets/generated/iconfont/iconfont.ttf'), // eslint-disable-line global-require
            // This is the font that we are using for our tab bar
            // This is the font used by react-native-paper

First things first, the require statements throw errors, how do I prevent that? It seems like no matter what I do the code in useEffect gets called after the test ends.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.