React-Native-Testing-Library '警告 - 更新未包含在 act(...)

我认为有人问过这个问题,但没有提供解决方案。

我正在使用 RNTL 尝试对一个简单的 RN 组件进行单元测试。

我的例子如下:

    component = render(<ThemeProvider>
      <NavigationContainer>
        <LandingScreen />
      </NavigationContainer>
    </ThemeProvider>
    );
  });

  afterEach(() => {
    cleanup();
  });


it('renders the main title correcty',async () => {
    const { findByText } = component;
    const heading = await waitFor(() => findByText('Bringing Banking into the Future'));
    expect(heading).toBeTruthy()
  })

我已经尝试了许多不同的等待使用它,没有 await waitFor() 并且我不断收到相同的错误(见下文)

      
      When testing,code that causes React state updates should be wrapped into act(...):
      
      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */

我还尝试了此处提到的所有内容:https://github.com/callstack/react-native-testing-library/issues/379#issuecomment-714341282,包括将 findBy 替换为 getBy 不走运。

欢迎提出任何想法!

谢谢

hui290021617 回答:React-Native-Testing-Library '警告 - 更新未包含在 act(...)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1031103.html

大家都在问