简体   繁体   中英

How to check the component type of a component's props?

I've got quite a simple FormControlLabel , with components for the 'control' and the 'label':

  const MyComponent = () =>
    <FormControlLabel
      control={<CheckBox />}
      label={<Typography>Check please!</Typography}
    />

And in my tests I'd like to check I have the right components, where wrapper is my component from above:

it('uses a checkbox for the control', function() {
  expect(wrapper.prop('control').type()).to.equal(Checkbox);
})

Except I get `TypeError wrapper.prop(...).type is not a function.

If I print out what wrapper.prop('control') is I get an object with a type object but not a function.

If I wrap each prop with shallow I am now equality checking the components and they don't match. (This is not what I expected to have to do)

I can't see how to get type() to work.

How can I check the type of the props?

I have managed to get it working with:

expect(wrapper.prop('control').type).to.deep.equal(Checkbox);

Although I do not know if this is the neatest way to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM