Skip to content

Commit

Permalink
💥 Add jest tips
Browse files Browse the repository at this point in the history
  • Loading branch information
YenHub committed Dec 1, 2023
1 parent 9312ad8 commit 2b1483e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/engineering/javascript/jest/helpful-tips.md
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
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ nav:
- Default .eslintrc: engineering/javascript/node/eslintrc.md
- Colourful Console Logging: engineering/javascript/node/colour-logging.md
- NPKill - node_modules: engineering/javascript/node/node-cleanup.md
- Jest:
- Helpful Tips: engineering/javascript/jest/helpful-tips.md
- Ruby:
- Handling JSON: engineering/ruby/handling-json.md
- Git:
Expand Down

0 comments on commit 2b1483e

Please sign in to comment.