Adds to hasClass the ability to search using regex expression #1987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using a framework that injects JSS (decorators) like material-ui, it becomes complicated to deal with class searching.
There are some conditions, especially when dealing with transitions, when adding and removing a react component affects the UX. Ex. there is no fade-out animation when the component just vanishes away from the user screen.
{ show && <MyFadeOutComponent /> }
So one way to tackle this problem is to add and remove classes to the component, instead of rendering off the react component, when removing the class the transitions will work fine.
{ <MyFadeInAndFadeOutComponent className="hide" />
Testing this situation using decorators is tricky; You can export a version of the component before the injection as most people do in the storybook to show the correct propTypes, but sometimes it will require more work to be accomplished.
export const UndecoredMyComponent = MyComponent; export default withStyles(styles, { theme: true })(MyComponent);
Another approach: you can mock the decorator.
Therefore would be great to add to hasClass function the ability to search using a regex, it makes those conditions above easier to test.
// Should pass if is hiding the component (using class) expect(hasClassName(node, /(MyComponent)-(hide)-(\d+)/)).to.equal(true);