Jest: Add a configuration option to disable warnings

Created on 2 Mar 2015  Â·  10Comments  Â·  Source: facebook/jest

Hi guys, and thanks for the great work you put in React and Jest, these are pretty good tools and AFAIK they're only going to get better.

I think a configuration option for Jest to disable the printing of warnings in the console when running tests might be useful. In my case, I'm testing components making use of contentEditable, and I get plenty of :

A component is `contentEditable` and contains `children` managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.

Since the recommandation given about that warning in general was "if you know what you're doing, feel free to ignore this warning" (see this React issue), I think people in my situation (and maybe others, as I don't know every case where React throws a warning) would benefit from it, as a cleaner console for tests results is always appreciated.

It could be even better to be able to disable this specific warning in React in the first place (on a per-component basis, maybe ?), but I'll let you guys judge what is best.

Thanks !

Most helpful comment

You can pass in a --silent option now. works for me ¯\_(ツ)_/¯ no console outputs.

All 10 comments

In React that just uses console.warn. Disabling the logging across the board is probably a bad idea (and actually internally, we make warnings fail tests). Instead when we know a component will warn and that it's _ok_, we spyOn(console, 'warn') and then check that the warning was fired. With some exceptions (this particular one for example), it's we think generally a good idea to consider warnings as something you _must_ fix.

In your case it might make sense to do that as well, just when testing the components using contentEditable. In React itself we'll consider making that warning a little less noisy so it's easier to use when you know what you're doing.

Sounds fair to me. For the record, I did that in Jest with :

console.warn = jest.genMockFunction();
someCallTriggeringTheWarningANumberOfTimes();
expect(console.warn.mock.calls.length).toBeGreaterThan(0);

Thanks for your answer and your consideration of toning down a bit this warning in React, and keep up the good work :)

+1 for less noisy warning

+1

+1

In my case I have a contenteditable div, for plaintext only (because textareas are terrible), and I'm explicitly capturing the text and making sure it stays in sync with React. Nonetheless, my app will ship with warnings in production. Boo.

Yep, this is best handled inside of tests themselves. Another solution is to set the global DEV to false.

This no longer works. The warnings are actually console.error, even though they're not breaking javascript

You can pass in a --silent option now. works for me ¯\_(ツ)_/¯ no console outputs.

Aftter using it, I think --silent is an option for every console.*.
There are some needless warnings from other libraries, so sometimes I need this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kentor picture kentor  Â·  3Comments

Secretmapper picture Secretmapper  Â·  3Comments

StephanBijzitter picture StephanBijzitter  Â·  3Comments

paularmstrong picture paularmstrong  Â·  3Comments

kgowru picture kgowru  Â·  3Comments