TypeError:' undefined'不是一个对象(评估' this.props.people.map')

时间:2015-06-03 01:51:57

标签: reactjs

  1. 我得到了' 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 );
    
  2. 另外,我有一个测试用例来检查&#34; person-list有一个每个人的实例&#34;。但它也失败了。这是测试用例和错误消息

    it( `has an instance for every person`, () => {
       let persons = scryRenderedComponentsWithType( list, PersonItem );
       expect( persons.length ).to.equal( people.length );
    } );
    
  3. PhantomJS 1.9.8(Windows 7 0.0.0)person-list有一个每个人失败的实例         AssertionError:预期1等于2

    1. 我有另一个测试用例,以确保没有额外的元素。但它也失败了。这是测试用例和错误

      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 );
      
      } );
      
    2. PhantomJS 1.9.8(Windows 7 0.0.0)person-list没有额外的元素FAILED         圆顶感知&#34;错误:SYNTAX_ERR:DOM例外12&#34;被抛出,抛出一个错误:)

0 个答案:

没有答案