Enzyme: type() and is() not working properly?

Created on 6 Feb 2017  路  6Comments  路  Source: enzymejs/enzyme

Let's say that I have a component <BaseImg/> and I want to create another component <TripleImg/> that extends <BaseImg/>.
If I do shallow(<TripleImg/>).type() it will be BaseImg.

Why is that? Is this intended?

question

All 6 comments

By extend, do you mean you are doing this?

class BaseImg extends React.Component { /* ... */ }
class TripleImg extends BaseImg { /* ... */ }

Yes

I don't think this is an issue with Enzyme as we read the type off of the component. I can't find any links right now, but I remember reading about how you shouldn't make components extend from other components...

This thread might help you get your prototype setup correctly: https://github.com/facebook/react/issues/4878

I'm going to close the ticket for now as it doesn't seem like an issue with Enzyme. Feel free to keep the conversation going for support. If it proves to be an issue with Enzyme we can re-open and address it.

I see. Thank you for the clarification. I'll keep looking into it and will write my findings here (if any).

@raduanastases idiomatic React does not ever use inheritance to extend components; you should seriously consider not doing that, and using composition instead.

@ljharb I know, I'll bring it up in my team and maybe we will move to composition. Thanks for the info.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timhonders picture timhonders  路  3Comments

abe903 picture abe903  路  3Comments

ivanbtrujillo picture ivanbtrujillo  路  3Comments

blainekasten picture blainekasten  路  3Comments

andrewhl picture andrewhl  路  3Comments