Skip to content

Commit

Permalink
update docs to describe usage of COLORS env variable #1166
Browse files Browse the repository at this point in the history
  • Loading branch information
MynockSpit committed Sep 15, 2022
1 parent 0bcd351 commit 2bd3866
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions docs/dom-testing-library/api-debugging.mdx
Expand Up @@ -5,8 +5,8 @@ title: Debugging

## Automatic Logging

When you use any `get` calls in your test cases, the current state of the
`container` (DOM) gets printed on the console. For example:
When any `get` or `find` calls you use in your test cases fail, the current
state of the `container` (DOM) gets printed on the console. For example:

```javascript
// <div>Hello world</div>
Expand All @@ -26,7 +26,7 @@ Here is the state of your container:
</div>
```

Note: Since the DOM size can get really large, you can set the limit of DOM
**Note**: Since the DOM size can get really large, you can set the limit of DOM
content to be printed via environment variable `DEBUG_PRINT_LIMIT`. The default
value is `7000`. You will see `...` in the console, when the DOM content is
stripped off, because of the length you have set or due to default size limit.
Expand All @@ -40,6 +40,20 @@ This works on macOS/Linux, you'll need to do something else for Windows. If
you'd like a solution that works for both, see
[`cross-env`](https://www.npmjs.com/package/cross-env).

**Note**: The output of the DOM is colorized by default if your tests are
running in a node environment. However, you may sometimes want to turn off
colors, such as in cases where the output is written to a log file for
debugging purposes. You can use the environment variable `COLORS` to explicitly
force the colorization off or on. For example:

```
COLORS=false npm test
```

This works on macOS/Linux, you'll need to do something else for Windows. If
you'd like a solution that works for both, see
[`cross-env`](https://www.npmjs.com/package/cross-env).

## `prettyDOM`

Built on top of
Expand Down Expand Up @@ -76,7 +90,7 @@ This function is usually used alongside `console.log` to temporarily print out
DOM trees during tests for debugging purposes:

```javascript
import {prettyDOM } from '@testing-library/dom'
import {prettyDOM} from '@testing-library/dom'

const div = document.createElement('div')
div.innerHTML = '<div><h1>Hello World</h1></div>'
Expand Down

0 comments on commit 2bd3866

Please sign in to comment.