Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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
Javascript 使用磁带测试react onClick事件_Javascript_Reactjs_Onclick_Babeljs - Fatal编程技术网

Javascript 使用磁带测试react onClick事件

Javascript 使用磁带测试react onClick事件,javascript,reactjs,onclick,babeljs,Javascript,Reactjs,Onclick,Babeljs,我想在React with Tape上测试onClick事件。文档中说,您所要做的就是在比较之前直接调用onClick事件回调。但是当我在比较之前调用handleSubmit事件时,我得到一个错误——handleSubmit没有定义 import React, { Component, PropTypes } from 'react' import {createRenderer} from 'react-addons-test-utils'; import tape f

我想在React with Tape上测试onClick事件。文档中说,您所要做的就是在比较之前直接调用onClick事件回调。但是当我在比较之前调用handleSubmit事件时,我得到一个错误——handleSubmit没有定义

    import React, { Component, PropTypes } from 'react'
    import {createRenderer} from 'react-addons-test-utils';
    import tape from 'tape';
    import addAssertions from 'extend-tape';
    import jsxEquals from 'tape-jsx-equals';

    const test = addAssertions(tape, {jsxEquals});

    class MyComponent extends Component{
      constructor(props) {
            super(props)
            this.state = {text: 'here is text'}
      }
      handleSubmit(e){
            this.setState({text: 'new text'})
      }
      render() {
        return (
            <div>
              {this.state.text}
              <button onClick={(e) => this.handleSubmit(e)}>Update</button>
            </div>
        );
      }
    };

    test('MyComponent is properly rendered', (t) => {
        t.plan(1);
        const text = 'here is text'
        const renderer = createRenderer();
        renderer.render(<MyComponent />);
        const result = renderer.getRenderOutput();
        handleSubmit();
        t.jsxEquals(result, <div>{text}<button onClick={(e) => this.handleSubmit(e)}>Update</button></div>);
        t.end();
    });
import React,{Component,PropTypes}来自“React”
从“react addons test utils”导入{createRenderer};
从“磁带”导入磁带;
从“扩展磁带”导入addAssertions;
从“tape jsx equals”导入jsxEquals;
const test=addAssertions(磁带,{jsxEquals});
类MyComponent扩展组件{
建造师(道具){
超级(道具)
this.state={text:'这里是text'}
}
handleSubmit(e){
this.setState({text:'newtext'})
}
render(){
返回(
{this.state.text}
this.handleSubmit(e)}>Update
);
}
};
测试('MyComponent正确呈现',(t)=>{
t、 计划(1);
const text='这里是文本'
const renderer=createRenderer();
render.render();
const result=renderer.getrenderroutput();
handleSubmit();
t、 jsxEquals(结果,{text}this.handleSubmit(e)}>Update);
t、 end();
});