【问题标题】:How to test useParam() function with Jest如何使用 Jest 测试 useParam() 函数
【发布时间】:2020-11-30 08:30:50
【问题描述】:

在测试具有钩子 useParam() 的组件时出现此错误

【问题讨论】:

  • 可以分享一下测试代码吗?
  • @Megha Rawat 我也有同样的错误。你是怎么解决的?
  • 希望我刚刚发布的答案,对你有帮助:)

标签: reactjs jestjs react-hooks


【解决方案1】:
I fixed it using below code.
  jest.mock('react-router-dom', () => ({
    ...jest.requireActual('react-router-dom'),
    useParams: () => ({
      connectionId: '12',
    }),
  }));

【讨论】:

    猜你喜欢
    • 2020-06-22
    • 2020-10-29
    • 1970-01-01
    • 2019-07-22
    • 2017-09-18
    • 2019-01-04
    • 1970-01-01
    • 2022-01-24
    • 2020-01-24
    相关资源
    最近更新 更多