Skip to content

Commit f66b74d

Browse files
kalpeshsinghrickhanlonii
authored andcommitted
Updates SnapshotTesting.md to provide more info. on snapshot scope (#6735)
* Updates SnapshotTesting.md to provide more info. on snapshot scope The doc doesn't mention where to look for the bugs in the code. I have added extra info. which will clear things to find the bugs and why does test pass when you doesn't add any props in the component used in different files. As a beginner I thought, test will fail if I change Link component props in the any file that usage test component (in this case Link component). * Lints file * Calls out code
1 parent 56411e0 commit f66b74d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

docs/SnapshotTesting.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ exports[`renders correctly 1`] = `
3939
`;
4040
```
4141

42-
The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs Jest will simply compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code that should be fixed, or the implementation has changed and the snapshot needs to be updated.
42+
The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs Jest will simply compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in this case, it's `<Link>` component) that should be fixed, or the implementation has changed and the snapshot needs to be updated.
43+
44+
> Note: The snapshot is directly scoped to the data you render – in our example it's `<Link />` component with page prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `<Link />` component, it will still pass the test as the test doesn't know the usage of `<Link />` component and it's scoped only to the `Link.react.js`.
45+
> Also, Rendering the same component with different props in other snapshot test will not affect the first one, as the tests don't know about each other.
4346
4447
More information on how snapshot testing works and why we built it can be found on the [release blog post](https://jestjs.io/blog/2016/07/27/jest-14.html). We recommend reading [this blog post](http://benmccormick.org/2016/09/19/testing-with-jest-snapshots-first-impressions/) to get a good sense of when you should use snapshot testing. We also recommend watching this [egghead video](https://egghead.io/lessons/javascript-use-jest-s-snapshot-testing-feature?pl=testing-javascript-with-jest-a36c4074) on Snapshot Testing with Jest.
4548

0 commit comments

Comments
 (0)