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

Make hasClass work for mounted composite components #677

Conversation

christian-schulze
Copy link
Contributor

This (hopefully?) address the long running issue #134, where wrapper.hasClass always returns false on mounted composite components. The reason for the failure is the following block in MountedTraversal.js#instHasClassName:

  if (!isDOMComponent(inst)) {
    return false;
  }

Simply removing this block breaks many things, as the method is used internally in MountedTraversal.js. My naive solution is to split the method in two, so we retain the exported instHasClassName function for use by ReactWrapper.hasClass, and extract a private hasClassName function for use internally in MountedTraversal.js.

From here we can remove the !isDOMComponent early exit code from instHasClassName, and instead add it to hasClassName to maintain existing functionality.

…assName, which allows ReactWrapper.hasClass to bypass the !isDOMComponent(inst) call
const wrapper = mount(
<div className="foo bar baz some-long-string FoOo" />,
);
context('When using a DOM component', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ljharb are you OK with using context blocks here? I don't think we use them anywhere else, but it makes enough sense.

Copy link
Member

Choose a reason for hiding this comment

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

context and describe are identical - either is fine, but i have a light preference for describe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, I know they're identical, it was just a question of preference.

Copy link
Collaborator

@aweary aweary left a comment

Choose a reason for hiding this comment

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

Approved, assuming we're OK with using that context block in the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants