glenjamin / skin-deep

Test assertion helpers for use with React's shallowRender test utils
MIT License
200 stars 40 forks source link

Support component names when created as ES2015 classes #11

Closed evocateur closed 8 years ago

evocateur commented 8 years ago

Based on the discussion of this Babel issue and the solution in this pull request, this adds a getComponentName() function that provides a forward-looking fallback to the static displayName property.

Unfortunately, writing a test to validate this in the current setup is impossible, as it requires a Babel pipeline. I've linked it locally into a project that uses ES2015 classes for React components, and it works swimmingly. The change is fully backward-compatible, in any case.

glenjamin commented 8 years ago

Looks sensible. You don't need a babel pipeline for the test though, you just need to write similar code to what babel would produce, which is:

function MyComponent() {}
MyComponent.prototype = Object.create(React.Component);
MyComponent.prototype.render = function() {
  return <div />;
}

Classes are just functions, in the above example, MyComponent.name == 'MyComponent'.

glenjamin commented 8 years ago

Added a test via cfb3c18

evocateur commented 8 years ago

I'm still pretty new to the whole Babel + ES2015 + React ecosystem. Thanks for correcting my misunderstanding!

glenjamin commented 8 years ago

There's a bit of a backlog on travis at the moment, but once it catches up I'll cut a new release.

evocateur commented 8 years ago

Awesome, thanks.

On Sep 26, 2015, at 08:40, Glen Mailer notifications@github.com wrote:

There's a bit of a backlog on travis at the moment, but once it catches up I'll cut a new release.

— Reply to this email directly or view it on GitHub.

glenjamin commented 8 years ago

v0.6.1