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

Fix jest-emotion for preact #731

Merged
merged 1 commit into from
Jun 20, 2018

Conversation

aaronjensen
Copy link
Contributor

@aaronjensen aaronjensen commented Jun 18, 2018

What:

Preact, when rendered by preact-render-to-json does not always have props, so we
need to account for this.

Why:

So it works.

How:

Assume no classes if there are no props.

Checklist:

  • Documentation N/A
  • Tests
  • Code complete

@aaronjensen aaronjensen changed the title <!-- Fix jest-emotion for preact Jun 18, 2018
@Andarist
Copy link
Member

Could u add a test for this?

@aaronjensen
Copy link
Contributor Author

Probably not easily. I don’t have time to do it right now. I mentioned this in the PR

@aaronjensen
Copy link
Contributor Author

@Andarist just added a test.


it('replaces class names and inserts styles into preact test component snapshots', () => {
const tree = render(
<div class={divStyle}>
Copy link
Member

Choose a reason for hiding this comment

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

is preact accepting class instead of className?

There is a linting problem found in this file:

Unknown property 'class' found, use 'className' instead react/no-unknown-property

If class is correct in preact you can just disable this rule for this file (with top file comment or smth)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed. And yes, preact takes all the html style instead of js style (class and for, for example)

@@ -6,7 +6,7 @@ function getClassNames(selectors, classes) {

function getClassNamesFromTestRenderer(selectors, node) {
const props = node.props
return getClassNames(selectors, props.className || props.class)
return props ? getClassNames(selectors, props.className || props.class) : []
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be : selectors instead of : []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, fixed.

Apparently preact doesn't always give props, so we need to deal with that.
@tkh44
Copy link
Member

tkh44 commented Jun 20, 2018

Thanks for the PR @aaronjensen

Copy link
Member

@emmatown emmatown left a comment

Choose a reason for hiding this comment

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

Thanks!!

@emmatown emmatown merged commit 5c88af9 into emotion-js:master Jun 20, 2018
@aaronjensen aaronjensen deleted the fix-jest-emotion-preact branch June 21, 2018 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants