【问题标题】:React IonDateTime does not render in Jest testReact IonDateTime 不会在 Jest 测试中呈现
【发布时间】:2021-09-01 17:09:48
【问题描述】:

在 Ionic React 组件上运行 Jest 时,无论组件是否接收到时间值,以下测试都会失败。

test('IonDateTime appears', () => {
  render(<IonDatetime data-testid="foo" mode="ios" />);
  const dateTimeComponent = screen.getByTestId('foo');

  expect(dateTimeComponent).toBeInTheDocument();
});

这是 Jest 的输出,其中 body 返回一个空 div。

    TestingLibraryElementError: Unable to find an element by: [data-testid="foo"]
    <body>
      <div />
    </body>

我的 setupTests.ts 文件中有 mockIonicReact();,它应该允许不同的 Ionic 组件在 JSDOM 中呈现。

【问题讨论】:

    标签: reactjs typescript ionic-framework jestjs


    【解决方案1】:

    在 mockIonicReact.js 中,Jest 不能使用 mockController,除非分配给它的变量也以单词“mock”开头 之前回答于:

    截至 2021 年 6 月 16 日,Ionic React 中仍然存在错误 (view here)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-02
      • 2021-07-19
      • 2018-04-17
      • 2022-12-03
      • 1970-01-01
      • 2021-08-07
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多