Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/rules/no-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const utils = render(<Hello />);
utils.debug();
```

If you use [custom render functions](https://testing-library.com/docs/example-react-redux) then you can set a config option in your `.eslintrc` to look for these.

```
"testing-library/no-debug": ["error", {"renderFunctions":["renderWithRedux", "renderWithRouter"]}],
```

## Further Reading

- [debug API in React Testing Library](https://testing-library.com/docs/react-testing-library/api#debug)
21 changes: 19 additions & 2 deletions lib/rules/no-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,35 @@ module.exports = {
noDebug: 'Unexpected debug statement',
},
fixable: null,
schema: [],
schema: [
{
type: 'object',
properties: {
renderFunctions: {
type: 'array',
},
},
},
],
},

create: function(context) {
let hasDestructuredDebugStatement = false;
const renderVariableDeclarators = [];

let renderFunctions = [];
if (context.options && context.options.length > 0) {
[{ renderFunctions }] = context.options;
}

return {
VariableDeclarator(node) {
if (
node.init &&
node.init.callee &&
node.init.callee.name === 'render'
['render', ...renderFunctions].some(
name => name === node.init.callee.name
)
) {
if (
node.id.type === 'ObjectPattern' &&
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ ruleTester.run('no-debug', rule, {
},
],
},
{
code: `
const { debug } = renderWithRedux(<Component/>)
debug()
`,
options: [
{
renderFunctions: ['renderWithRedux'],
},
],
errors: [
{
messageId: 'noDebug',
},
],
},
{
code: `
const utils = render(<Component/>)
Expand Down