0

我想为 App 组件编写一个测试,以检查是否按顺序调用了预期的服务操作。与其他组件不同,我被困在如何访问应用程序本身,因为它抛出“元素类型无效

应用程序.ts

import {ServiceA, ServiceB, ServiceC} from './services'
export const App = () => {
  const Stack = createStackNavigator();
  ...

  useEffect(() => {
    const bootstrap = async () => {

      let r1 = await ServiceC.someMethod()
      let r2 = await ServiceA.asyncMethodA(r1)
      if(r2=='A')
           await ServiceB.someMethod()
      ...
    };
    bootstrap();
  }, []);

  return (
    <NavigationContainer>
      <Stack.Navigator
        screenOptions={{
          headerShown: false,
        }}>
        <Stack.Screen... />
        <Stack.Screen... />
        <Stack.Screen... />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

如何更新以下测试功能以监视服务操作并验证它们是否按预期顺序调用?

import React from 'react';
import {fireEvent, render} from 'react-native-testing-library';
import {App} from '../../App';

describe('Root App', () => {
  it('Check the flow ', () => {
    let Application = render(<App />);
  });
});
4

0 回答 0