reactjs - Enzyme: Method “text” is only meant to be run on a single node. 0 found instead -


i'm using react v15.4, babel-jest v18 , enzyme v2.5.1

i have simple react component:

import react, {component} 'react' import {formattedrelative} 'react-intl' import pagewithintl '../components/pagewithintl' import layout '../components/layout'  class extends component {   static async getinitialprops ({req}) {     return {somedate: date.now()}   }    render () {     return (       <layout>         <h1>about</h1>         <p>           <formattedrelative             value={this.props.somedate}             updateinterval={1000}           />         </p>       </layout>     )   } }  export default pagewithintl(about) 

and simple jest/enzyme test:

/* global it, expect, describe */  import react 'react' import { shallow } 'enzyme' import renderer 'react-test-renderer' import '../pages/about.js'  describe('with enzyme', () => {   it('app shows "about"', () => {     const = shallow(       <about />     )     expect(about.find('h1').text()).toequal('about')   }) }) 

the jest test should pass i'm getting error:

method “text” meant run on single node. 0 found instead.

what missing?

=== update

the snapshot test passes:

describe('with snapshot testing', () => {   it('about shows "about"', () => {     const component = renderer.create(<about />)     const tree = component.tojson()     expect(tree).tomatchsnapshot()   }) }) 

is there way integrate enzyme expect test inside snapshot test? , how?

its caused fact shallow not render child componnets , component been wrapped function. shallow returns representation of function not of component. can use dive() reach real component

/* global it, expect, describe */  import react 'react' import { shallow } 'enzyme' import renderer 'react-test-renderer' import '../pages/about.js'  describe('with enzyme', () => {   it('app shows "about"', () => {     const = shallow(       <about />     ).dive()     expect(about.find('h1').text()).toequal('about')   }) }) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -