javascript - Issue using jest - Cannot read property 'xxx' of undefined -


i receive error using following test case:

 cannot read property 'weathericoncode' of undefined 

i passing weathericoncode component test case, not understand why undefined.

any ideas how solve brief explanation welcome.

component:

import react, {component} 'react'  import iconweather '../../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

test case:

import react 'react'  import {shallow} 'enzyme'  import tojson 'enzyme-to-json'  import summarycharticon './summarycharticon'    describe('<summarycharticon />', () => {    it('should render', () => {      const wrapper = shallow(        <summarycharticon weathericoncode={200} />        )      expect(tojson(wrapper)).tomatchsnapshot()    })  })

you should pass right property component, in case payload contain object called property weathericoncode

if change code follow should work.

describe('<summarycharticon />', () => {   it('should render', () => {     const wrapper = shallow(       <summarycharticon payload={{weathericoncode: 200}} />       )     console.log(wrapper.debug())     expect(tojson(wrapper)).tomatchsnapshot()   }) }) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -