score:1

Accepted answer

in order to refer to components, use their name not a string as documented:

wrapper.find(foo) // foo component, not 'foo'

i would like to check if there is a correct number of children components of the radiogroupfield component:

use children() as documented in the enzyme api

const radiogroupfield = wrapper.find(radiogroupfield).dive()
expect(radiogroupfield.children()).to.have.length(2)

references:

edit: add dive() as this may be needed to render components (non-dom nodes)

update

i have tried with using name and not string for the component and dive method, but all of a sudden i get an error:

referenceerror: radiogroupfield is not defined

any components used in your tests need to be imported.

here's an example:

foo.js:

import react from 'react'

export const bar = (props) => {
  return (
    <div>
      {props.children}
    </div>
  )
}

export const baz = () => (
  <div>foo</div>
)

export const foo = () => (
  <bar>
    <baz />
    <baz />
  </bar>
)

export default foo

foo.test.js

import react from 'react'
import { shallow } from 'enzyme'
import foo, { bar, baz } from './foo'

it('foos', () => {
  let wrapper = shallow(<foo />)
  expect(wrapper.find(bar)).tohavelength(1) // jest syntax
})

score:0

this also works:

const radiooption = wrapper.find(radiogroupfield).dive().find(radiooption);

Related Query

More Query from same tag