我得到了' undefined'运行测试用例时不是对象错误。这是实际的代码。
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 );
另外,我有一个测试用例来检查&#34; person-list有一个每个人的实例&#34;。但它也失败了。这是测试用例和错误消息
it( `has an instance for every person`, () => {
let persons = scryRenderedComponentsWithType( list, PersonItem );
expect( persons.length ).to.equal( people.length );
} );
PhantomJS 1.9.8(Windows 7 0.0.0)person-list有一个每个人失败的实例 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 );
} );
PhantomJS 1.9.8(Windows 7 0.0.0)person-list没有额外的元素FAILED 圆顶感知&#34;错误:SYNTAX_ERR:DOM例外12&#34;被抛出,抛出一个错误:)