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 serializer file #777

Merged
merged 5 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/jest-emotion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ npm install --save-dev jest-emotion

# Snapshot Serializer

The easiest way to test React components with emotion is with the snapshot serializer. (the example below is with react-test-renderer but jest-emotion also works with enzyme)
The easiest way to test React components with emotion is with the snapshot serializer. You can register the serializer via the `snapshotSerializers` configuration property in your jest configuration like so:

```js
// jest.config.js
module.exports = {
// ... other config
snapshotSerializers: [
'jest-emotion/serializer'
]
}
```

Or you can customize the serializer via the `createSerializer` method like so: (the example below is with react-test-renderer but jest-emotion also works with enzyme and react-testing-library)

```jsx
import React from 'react'
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"files": [
"src",
"dist",
"types"
"types",
"serializer.js"
],
"scripts": {
"test:typescript": "dtslint types"
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-emotion/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { createSerializer } = require('jest-emotion')
const emotion = require('emotion')

module.exports = createSerializer(emotion)