Skip to content

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

Merged
emmatown merged 4 commits into
emotion-js:masterfrom
rszewczyk:619-print-dom-elements
Apr 17, 2018
Merged

Add support to jest-emotion for printing DOM Elements (#619)#622
emmatown merged 4 commits into
emotion-js:masterfrom
rszewczyk:619-print-dom-elements

Conversation

@rszewczyk
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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!!

Comment thread packages/jest-emotion/README.md Outdated
)
```

### `disableDOMElements`
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

tkh44 commented Apr 25, 2018

Thank you @rszewczyk!

@kentcdodds
Copy link
Copy Markdown

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.

4 participants