【问题标题】:How to Jest.mock redux-form's Field如何 Jest.mock redux-form 的字段
【发布时间】:2017-08-29 10:15:43
【问题描述】:

我的 react 类组件如下所示:

import { Field, reduxForm, propTypes } from 'redux-form';

class DepositAmountInput extends Component {
  render() {
    return (
      <View>
        <Field
          component={NumberInputField}
          props={{
            onChange: this.handleInput,
            onBlur: this.handleOnBlur
          }}
        />
      </View>
    );
  }
}
export default DepositAmountInput

在我对此组件的 Jest 测试中,如何模拟 redux-form 的 Field 组件?我正在寻找这样的东西:

.mock('redux-form/lib/Field', () => 'Field');

谢谢!

【问题讨论】:

    标签: testing react-native react-redux jestjs


    【解决方案1】:

    这是在我的测试中运行良好的代码(见下图) jest.mock('redux-form/lib/Field', () => 'field'); (和你当时期待的一样。)

    在我的 pacakage.json 上: { "redux-form": "^7.0.3", "jest": "^20.0.4", }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-30
      • 2019-03-27
      • 2016-12-24
      • 1970-01-01
      • 2020-07-29
      • 2018-06-22
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多