【问题标题】:how to mock npm uniqid for react unit test when using Jest?使用 Jest 时如何模拟 npm uniqid 进行反应单元测试?
【发布时间】:2017-06-14 07:04:48
【问题描述】:

我正在尝试模拟 npm uniqid 库以进行反应单元测试。我已将此 uniqid 用于复选框。这是用于组件渲染测试。

【问题讨论】:

    标签: reactjs jestjs babel-jest


    【解决方案1】:

    你可以这样模拟它:

    jest.mock('uniqid', ()=>(i)=> i + 'someUniqId')
    

    或者如果您使用其他功能之一

    jest.mock('uniqid', () = > ({
      process: (i) => i + 'someProcess,
      time: (i) => i + ' someTime,
    }))
    

    【讨论】:

      猜你喜欢
      • 2018-12-28
      • 1970-01-01
      • 2020-09-13
      • 2016-03-05
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      相关资源
      最近更新 更多