File tree Expand file tree Collapse file tree 12 files changed +72
-2
lines changed
print-message-with-other-failure Expand file tree Collapse file tree 12 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,14 @@ failOnConsole({
194194})
195195```
196196
197+ ### shouldPrintMessage
198+
199+ Use this to print the message immediately when called not awaiting the test to finish. This is useful to show the message if there are
200+ other or earlier test failures which will result in the fail on console error to be hidden by jest.
201+
202+ - Type: ` boolean `
203+ - Default: ` false `
204+
197205## License
198206
199207[ MIT] ( https://github.com/ValentinH/jest-fail-on-console/blob/master/LICENSE )
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ declare namespace init {
5252 methodName : ConsoleMethodName ,
5353 context : { group : string ; groups : string [ ] }
5454 ) => boolean
55+
56+ /** @default false */
57+ shouldPrintMessage ?: boolean
5558 }
5659}
5760
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const init = ({
2424 skipTest,
2525 silenceMessage,
2626 allowMessage,
27+ shouldPrintMessage = false ,
2728} = { } ) => {
2829 const flushUnexpectedConsoleCalls = ( methodName , unexpectedConsoleCallStacks ) => {
2930 if ( unexpectedConsoleCallStacks . length > 0 ) {
@@ -72,6 +73,10 @@ const init = ({
7273 return
7374 }
7475
76+ if ( shouldPrintMessage ) {
77+ originalMethod ( format , ...args )
78+ }
79+
7580 // Capture the call stack now so we can warn about it later.
7681 // The call stack has helpful information for the test author.
7782 // Don't throw yet though b'c it might be accidentally caught and suppressed.
Original file line number Diff line number Diff line change 1+ module . exports = ( ) => {
2+ console . error ( 'my error message that I do not control' ) ;
3+ throw new Error ( 'some other error' ) ;
4+ }
Original file line number Diff line number Diff line change 1+ const consoleError = require ( '.' )
2+
3+ describe ( 'print message flag with other test failure' , ( ) => {
4+ it ( 'does not throw' , ( ) => {
5+ expect ( consoleError ) . not . toThrow ( )
6+ } )
7+ } )
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ setupFilesAfterEnv : [ './jest.setup.js' ] ,
3+ }
Original file line number Diff line number Diff line change 1+ const failOnConsole = require ( '../../..' )
2+
3+ failOnConsole ( {
4+ shouldFailOnError : true ,
5+ shouldPrintMessage : true ,
6+ } )
Original file line number Diff line number Diff line change 1+ module . exports = ( ) => {
2+ console . error ( 'my error message that I do not control' )
3+ }
Original file line number Diff line number Diff line change 1+ const consoleError = require ( '.' )
2+
3+ describe ( 'print message flag' , ( ) => {
4+ it ( 'does not throw' , ( ) => {
5+ expect ( consoleError ) . not . toThrow ( )
6+ } )
7+ } )
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ setupFilesAfterEnv : [ './jest.setup.js' ] ,
3+ }
You can’t perform that action at this time.
0 commit comments