Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 获取错误“;无法读取属性'__reactInternalInstance$a2hlbpvzpyeu9ywvcwjr1kyb9';“未定义”的定义;_Reactjs_Jasmine_Material Ui_Jestjs - Fatal编程技术网

Reactjs 获取错误“;无法读取属性'__reactInternalInstance$a2hlbpvzpyeu9ywvcwjr1kyb9';“未定义”的定义;

Reactjs 获取错误“;无法读取属性'__reactInternalInstance$a2hlbpvzpyeu9ywvcwjr1kyb9';“未定义”的定义;,reactjs,jasmine,material-ui,jestjs,Reactjs,Jasmine,Material Ui,Jestjs,我正在使用Jest测试以下材质UI组件。我想断言,单击RaisedButton组件时会调用handleSubmit函数 //Form.js export default class Form extends React.Component { <RaisedButton ref="buttonTag" className='SubmitButton' label='Go'

我正在使用Jest测试以下材质UI组件。我想断言,单击RaisedButton组件时会调用handleSubmit函数

        //Form.js

export default class Form extends React.Component {    

<RaisedButton
            ref="buttonTag"
            className='SubmitButton'
            label='Go'
            icon={<ActionSearch />}
            onClick={this.handleSubmit} />

        handleSubmit = (event) => {

        };
    }

    //Form-test.js

    import Form from '../../src/Components/Form/Form';
    import React from 'react';
    import TestUtils from 'react-dom/test-utils';

    let form = TestUtils.renderIntoDocument(
        <Form />
    );

    const spy = jest.spyOn(form, 'handleSubmit').mockImplementation(() => {});
    let buttonNode = form.refs.buttonTag; 
    TestUtils.Simulate.click(buttonNode);
    expect(spy).toHaveBeenCalled();
我得到以下错误:

"Cannot read property '__reactInternalInstance$a2hlbpvzpyeu9ywvcwjr1kyb9' of undefined"
如何正确模拟单击Raised按钮触发handleSubmit()?

而不是执行以下操作:

let buttonNode = form.refs.buttonTag; 
我是如何解决这个问题的,就是在按钮上放一个普通的jane
ID=“myID”
,然后像这样得到它:

const buttonNode = document.getElementById("myID");
然后做
TestUtils.Simulate.click(按钮节点)

此处相同。“我也是!”
const buttonNode = document.getElementById("myID");