Skip to content

Commit d8aa77c

Browse files
pedrottimarkcpojer
authored andcommitted
Add Usage in Jest to pretty-format/README.md (#4253)
* Add Usage in Jest to pretty-format/README.md * Correct typing mistake
1 parent fbd0708 commit d8aa77c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

packages/pretty-format/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,31 @@ const formatted2 = prettyFormat(renderer.create(element).toJSON(), {
145145
*/
146146
```
147147

148+
## Usage in Jest
149+
150+
For snapshot tests, Jest uses `pretty-format` with options that include some of its built-in plugins. For this purpose, plugins are also known as **snapshot serializers**.
151+
152+
To serialize application-specific data types, you can add modules to `devDependencies` of a project, and then:
153+
154+
In an **individual** test file, you can add a module as follows. It precedes any modules from Jest configuration.
155+
156+
```js
157+
import serializer from 'my-serializer-module';
158+
expect.addSnapshotSerializer(serializer);
159+
160+
// tests which have `expect(value).toMatchSnapshot()` assertions
161+
```
162+
163+
For **all** test files, you can specify modules in Jest configuration. They precede built-in plugins for React, HTML, and Immutable.js data types. For example, in a `package.json` file:
164+
165+
```json
166+
{
167+
"jest": {
168+
"snapshotSerializers": ["my-serializer-module"]
169+
}
170+
}
171+
```
172+
148173
### Plugins
149174

150175
Pretty format also supports adding plugins:

0 commit comments

Comments
 (0)