Skip to content

Commit

Permalink
Merge branch 'main' into doc/redux-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioAslau authored Sep 6, 2024
2 parents ab13cf5 + 0604315 commit e84ba8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,35 @@ Jest incorporates most of the features of Sinon with a slimmer API:
- `jest.fn()` can be used in place of `sinon.stub()`.
- `jest.spyOn(object, method)` can be used in place of `sinon.spy(object, method)` or `sinon.stub(object, method)` (with the caveat that the method being spied upon will still be called by default).
- `jest.useFakeTimers()` can be used in place of `sinon.useFakeTimers()` (though note that Jest's "clock" object had fewer features than Sinon's prior to Jest v29.5).

## Snapshots

Jest snapshots are not testing the validity of the value tested against a snapshot.
It only checks for changes since last snapshot generation.

Never consider that rendering a component and matching the snapshot is a test of the component:
It will only check that the component render worked.
It may be an error screen and not the actual component.

To make this clear, name your snapshot test cases by the following rules:

🚫 Wrong naming

```ts
describe('MyComponent', () => {
it('should renders correctly')
```
✅ Correct naming
```ts
describe('MyComponent', () => {
it('render matches snapshot')
```
Of course variants of this naming can be used to add some context, for instance:
```ts
describe('MyComponent', () => {
it('render matches snapshot when not enabled'
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e84ba8c

Please sign in to comment.