airbnb / react-with-styles

Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable wrapping `displayName` with `withStyles(…)`

toddw opened this issue · comments

We use enzyme in our tests and it lets you use selectors like wrapper.find("MyComponent") but because of how react-with-styles renames the displayName we have to use wrapper.find("withStyles(MyComponent").

The line causing this is here:

WithStyles.displayName = `withStyles(${wrappedComponentName})`;

Would you be open to merging something that would allow us to make this optional?

Hi @toddw! Thanks for the question!

It is best to use wrapper.find() with a reference to the component instead of a string that describes the component (e.g. wrapper.find(MyComponent), not wrapper.find("MyComponent")). This will solve this problem for you when using any HOC, while also avoiding accidentally finding a different component than the one you expected that may have the same name.