-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Helpful Jest Tips | ||
|
||
## Debug the DOM | ||
|
||
```typescript | ||
import { render, screen } from '@testing-library/react' | ||
|
||
describe('debug the dom', () => { | ||
it('shows the DOM tree', () => { | ||
// Render something | ||
render(<div>Hello</div>) | ||
|
||
// Debug the DOM tree in the console | ||
screen.debug() | ||
|
||
// Test something | ||
expect(screen.getByText('Hello')).toBeInTheDocument() | ||
}) | ||
}) | ||
``` | ||
|
||
## Increase the number of debug lines printed | ||
|
||
This is helpful if you can't see the full output for a test failure. | ||
|
||
```bash | ||
DEBUG_PRINT_LIMIT=1000000 npx jest | ||
``` | ||
|
||
## Force tests to run in series | ||
|
||
This is handy when you're debugging test logs but they're out of sync. | ||
|
||
```bash | ||
npx jest --runInBand | ||
``` | ||
|
||
## Improve test speeds | ||
|
||
Use this flag to run across more available cores. | ||
|
||
```bash | ||
# You get a worker per core, so this uses 8 cores: | ||
npx jest --max-workers=8 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters