TypeError:无法读取未定义的属性“ bind”-ReactJS-测试库

时间:2019-05-03 15:21:17

标签: reactjs react-redux enzyme

我正在为容器上的render部分编写测试,测试按钮是否正确渲染。下面是已使用的代码

it('should render translation inputs', () => {
            const wrapper = shallow(<COAForwardTranslations store ={storeData}/>)
            expect(wrapper.find('.btn-primary').length).toBe(1);

      });

我收到“ TypeError:无法读取未定义的属性'bind'”,请您帮我,我已经重新安装

npm install --save-dev jest
npm install --save-dev babel-jest regenerator-runtime

但是我仍然得到错误。

仅检查按钮是否在容器上正确呈现,我在做错什么事情。

class COAForwardTranslations extends Component
{
    constructor(props, context) {
        super(props, context);
        this.state = {
                SegmentMapRequest : {
                BranchCode: '',
                GroupId: '',
                GlCompanyCode: '',
                GlAccount: '',
                SourceMode: '',
                SourceSystem: '',
                JournalCategory: '',
                EffectiveDate: ''
            },
            segmentMapResponse:{}
        }
        this.handleRequestChange = this.handleRequestChange.bind(this);
        this.handleForwardTranslation = this.handleForwardTranslation.bind(this);
        this.handleReset = this.handleReset.bind(this);
    }

    handleRequestChange(e){
        let inputName = e.target.name;
        let inputValue = e.target.value;
        let requestCopy = Object.assign({}, this.state.SegmentMapRequest);
        requestCopy[inputName] = inputValue;
        this.setState({SegmentMapRequest: requestCopy});
    }
    handleForwardTranslation(e)
    {
        e.preventDefault();
        this.props.getForwardTranslation(this.state.SegmentMapRequest);
    }
handleReset()
    {
        this.setState({SegmentMapRequest: {
            BranchCode: '',
                GroupId: '',
                GlCompanyCode: '',
                GlAccount: '',
                SourceMode: '',
                SourceSystem: '',
                JournalCategory: '',
                EffectiveDate: ''
            },
            segmentMapResponse : {}
        });
    }

1 个答案:

答案 0 :(得分:0)

问题出在

this.handleReset = this.handleReset.bind(this);

this.handleReset不存在于您的代码中,因此当您尝试在其上调用.bind()时,它将引发该错误。

相关问题