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
ReactJS测试:无法读取属性';拥有';未定义的_Reactjs_Jestjs_Enzyme - Fatal编程技术网

ReactJS测试:无法读取属性';拥有';未定义的

ReactJS测试:无法读取属性';拥有';未定义的,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我正试图为我的代码编写我的第一个测试,但我在让最基本的东西正常工作方面遇到了困难。以下是我所拥有的: //namePlate.js import React from 'react'; const NamePlate = (props)=>( <div className = 'namePlate' style = {props.color(props.name)}> {props.name} <button id = {props.id} type

我正试图为我的代码编写我的第一个测试,但我在让最基本的东西正常工作方面遇到了困难。以下是我所拥有的:

//namePlate.js
import React from 'react';

const NamePlate = (props)=>(
  <div className = 'namePlate' style = {props.color(props.name)}>
    {props.name}
    <button id = {props.id} type = 'button' onClick = {props.onClick}>x</button>}
  </div>
)

export default NamePlate

//namePlate.test.js

import React from 'react';
import NamePlate from './namePlate.js';
import {shallow} from 'enzyme';


it('renders', () => {
  const wrapper = shallow(<NamePlate name = 'Test' id = '1' onClick ={() =>{}} color = {()=>{}}/>);
  expect(wrapper.find('div')).to.have.lengthOf(1);

})
//emplate.js
从“React”导入React;
常数铭牌=(道具)=>(
{props.name}
x}
)
导出默认铭牌
//http://www.test.js
从“React”导入React;
从“/nametame.js”导入铭牌;
从“酶”导入{shall};
它('呈现',()=>{
常量包装=浅({}}color={()=>{}}/>);
expect(wrapper.find('div')).to.have.lengthOf(1);
})
我得到“TypeError:无法读取未定义的属性'have'”,我真的不确定我做错了什么。感谢您的帮助

expect(wrapper.find('div')).toHaveLength(1);