let firstError = undefined ; const hadConsoleError = function ( ) { return firstError !== undefined ; } ; const clearConsoleError = function ( ) { firstError = undefined ; } ; const catchConsoleErrors = function ( ) { let oldConsoleError , oldConsoleAssert ; beforeEach ( function ( ) { clearConsoleError ( ) ; oldConsoleError = console . error ; oldConsoleAssert = console . assert ; console . error = function ( e ) { if ( ! firstError ) { if ( typeof e === Error ) { firstError = e . stack ; } else { firstError = e ; } } oldConsoleError ( e ) ; } ; console . assert = function ( expression , text ) { oldConsoleAssert ( expression , text ) ; if ( ! firstError && ! expression ) { firstError = expression ; } } ; } ) ; afterEach ( function ( ) { console . error = oldConsoleError ; console . assert = oldConsoleAssert ; if ( firstError ) { should . fail ( true , false , firstError ) ; clearConsoleError ( ) ; } } ) ; } ; const oldConsoles = { } ; const numConsoleMessages = { } ; param { string } category const countConsoleMessages = function ( category ) { oldConsoles [ category ] = console [ category ] ; numConsoleMessages [ category ] = 0 ; console [ category ] = function ( ) { numConsoleMessages [ category ] ++ ; } ; } ; param { string } category return { Number } const endCountConsoleMessages = function ( category ) { console [ category ] = oldConsoles [ category ] ; return numConsoleMessages [ category ] ; } ; export { catchConsoleErrors , hadConsoleError , clearConsoleError , countConsoleMessages , endCountConsoleMessages } ;