2017-09-12 6 views
1

의 'xxx는' 정의되지 않는다.문제 속성을 읽을 수 없습니다 내가 다음 테스트 케이스를 사용하여 오류가 발생 정의되지 않은

간단한 아이디어로 해결하는 방법에 대한 아이디어는 매우 환영합니다.

구성 요소 :

import React, {Component} from 'react' 
 
import IconWeather from '../../shared/icon/IconWeather' 
 

 
class SummaryChartIcon extends Component { 
 
    render() { 
 
    const { cx, cy, payload: {weatherIconCode} } = this.props 
 
    return (
 
     <svg x={cx - 10} y={cy + 20}> 
 
     <foreignObject width='100%' height='100%'> 
 
      <IconWeather code={weatherIconCode} /> 
 
     </foreignObject> 
 
     </svg> 
 
    ) 
 
    } 
 
} 
 
export default SummaryChartIcon

테스트 케이스 :

import React from 'react' 
 
import {shallow} from 'enzyme' 
 
import toJson from 'enzyme-to-json' 
 
import SummaryChartIcon from './SummaryChartIcon' 
 

 
describe('<SummaryChartIcon />',() => { 
 
    it('should render',() => { 
 
    const wrapper = shallow(
 
     <SummaryChartIcon weatherIconCode={200} /> 
 
    ) 
 
    expect(toJson(wrapper)).toMatchSnapshot() 
 
    }) 
 
})

답변

2

당신은 당신을, 당신의 구성 요소에 적합한 속성을 통과해야 r 경우는 payload이고 다른 객체는 다음과 같습니다. weatherIconCode

다음 코드를 변경하면 작동합니다.

describe('<SummaryChartIcon />',() => { 
    it('should render',() => { 
    const wrapper = shallow(
     <SummaryChartIcon payload={{weatherIconCode: 200}} /> 
    ) 
    console.log(wrapper.debug()) 
    expect(toJson(wrapper)).toMatchSnapshot() 
    }) 
})