Reactjs 类型错误:';未定义';不是对象(评估';this.props.people.map';)
运行测试用例时,“未定义”不是对象错误。这是实际的代码Reactjs 类型错误:';未定义';不是对象(评估';this.props.people.map';),reactjs,Reactjs,运行测试用例时,“未定义”不是对象错误。这是实际的代码 class People extends React.Component{ displayAlert (email){ alert(email); } render (){ return ( <div>{ <ul key = {this.props.id}> <li> <button onCl
class People extends React.Component{
displayAlert (email){
alert(email);
}
render (){
return (
<div>{
<ul key = {this.props.id}>
<li>
<button onClick= {this.displayAlert.bind(this, this.props.email)}>{this.props.lastName + ', ' + this.props.firstName}</button>
</li>
</ul>}
</div>
);
}
}
class PersonList extends React.Component{
render () {
/* people is an array of people*/
var items = this.props.people.map( function ( item ){
return <People id = {item.id} email = {item.email} firstName = {item.firstName} lastName = {item.lastName}> </People>
});
return (
<div> {items} </div>
)
}
}
React.render( <PersonList people={ people } />, el );
PhantomJS 1.9.8(Windows 7 0.0.0)人员列表中的每个失败人员都有一个实例
AssertionError:应为1等于2
it( `doesn't have extra elements`, () => {
expect( domnode.querySelectorAll( '> :not( ul )' ).length ).to.equal( 0 );
expect( domnode.querySelectorAll( '> ul > :not( li )' ).length ).to.equal( 0 );
} );
抛出了DomeException“Error:SYNTAX\u ERR:DOM Exception 12”,抛出一个错误:)它还应该告诉您错误发生的确切位置。您能告诉我们如何设置测试数据和测试吗?
it( `doesn't have extra elements`, () => {
expect( domnode.querySelectorAll( '> :not( ul )' ).length ).to.equal( 0 );
expect( domnode.querySelectorAll( '> ul > :not( li )' ).length ).to.equal( 0 );
} );