github-pages-deploy-action/node_modules/eslint-plugin-jest/docs/rules/prefer-inline-snapshots.md

52 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2020-05-15 05:33:08 +08:00
# Suggest using inline snapshots (`prefer-inline-snapshots`)
2020-03-07 11:45:40 +08:00
2020-05-24 22:59:46 +08:00
## Deprecated
This rule has been deprecated in favor of
[`no-restricted-matchers`](no-restricted-matchers.md) with the following config:
```json
{
"rules": {
"jest/no-restricted-matchers": [
"error",
{
"toThrowErrorMatchingSnapshot": "Use `toThrowErrorMatchingInlineSnapshot()` instead",
"toMatchSnapshot": "Use `toMatchInlineSnapshot()` instead"
}
]
}
}
```
---
2020-09-13 06:19:45 +08:00
In order to make snapshot tests more manageable and reviewable
2020-03-07 11:45:40 +08:00
`toMatchInlineSnapshot()` and `toThrowErrorMatchingInlineSnapshot` should be
2020-09-13 06:19:45 +08:00
used to write the snapshots' inline in the test file.
2020-03-07 11:45:40 +08:00
## Rule details
This rule triggers a warning if `toMatchSnapshot()` or
`toThrowErrorMatchingSnapshot` is used to capture a snapshot.
The following pattern is considered warning:
```js
expect(obj).toMatchSnapshot();
```
```js
expect(error).toThrowErrorMatchingSnapshot();
```
The following pattern is not warning:
```js
expect(obj).toMatchInlineSnapshot();
```
```js
expect(error).toThrowErrorMatchingInlineSnapshot();
```