Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds to hasClass the ability to search using regex expression #1987

Merged
merged 1 commit into from
Jan 31, 2019

Conversation

stackchain
Copy link
Contributor

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);

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea! This seems reasonable to add.

CHANGELOG.md Outdated Show resolved Hide resolved
packages/enzyme-test-suite/package.json Outdated Show resolved Hide resolved
packages/enzyme-test-suite/test/RSTTraversal-spec.jsx Outdated Show resolved Hide resolved
packages/enzyme/src/RSTTraversal.js Outdated Show resolved Hide resolved
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks great!

@ljharb ljharb merged commit 20f1218 into enzymejs:master Jan 31, 2019
Make string selectors awesome automation moved this from Open to Closed/Merged Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants