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

Add support to jest-emotion for printing DOM Elements (#619) #622

Merged
merged 4 commits into from
Apr 17, 2018

Conversation

rszewczyk
Copy link
Contributor

@rszewczyk rszewczyk commented Apr 12, 2018

What:

Modifies the snapshot serializer plugin to:

  • add styles and replace class names in DOM Elements
  • add a configuration option to disable the above behavior

Why:

This will allow jest-emotion to work with libraries like react-testing-library

How:

  • Modifies test to check for and include DOM Elements (I borrowed the implementation details from the jest/pretty-format dom element plugin
  • Modify the function that gets all nodes in the tree to work with both React and DOM Elements
  • Add code to get selectors from DOM Elements

The test I wrote for this uses pretty-format directly in order to isolate them from the serializer used to test the rest of the packages.

Checklist:

  • Documentation
  • Tests
  • Code complete

@codecov
Copy link

codecov bot commented Apr 12, 2018

Codecov Report

Merging #622 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted Files Coverage Δ
packages/jest-emotion/src/index.js 92.3% <100%> (+0.64%) ⬆️

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 for the PR!!

@@ -57,6 +58,21 @@ expect.addSnapshotSerializer(
})
)
```

### `disableDOMElements`
Copy link
Member

Choose a reason for hiding this comment

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

Could you rename this option to DOMElements and make it so that it's true by default and making it false disables printing DOM elements' styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops! I forgot to update README.md accordingly. Done now.

describe('jest-emotion with dom elements', () => {
const emotionPlugin = createSerializer(emotion)

const divStyle = emotion.css(`
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this to use css as a tagged template literal like this?

css`
  color: red;
`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

rszewczyk and others added 3 commits April 16, 2018 10:54
  * use tagged template literals with `css`
  * reverse the configuration logic for DOM elements and have it enable by default
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 2a976ae into emotion-js:master Apr 17, 2018
@tkh44
Copy link
Member

tkh44 commented Apr 25, 2018

Thank you @rszewczyk!

@kentcdodds
Copy link
Contributor

This is awesome! Thanks!

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.

None yet

4 participants