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);