import { UnknownError } from './unknown-error' ; const functionThatThrowsAnError = ( ) => { throw Error ( 'Boo!' ) ; } ; const functionThatThrowsAString = ( ) => { throw 'Oh No!' ; } ; const wrapInUnknown = ( error ) => { return new UnknownError ( error ) ; } ; describe ( 'UnknownError' , ( ) => { it ( 'When created with an Error, UnknownError preserves the StackTrace' , ( ) => { try { functionThatThrowsAnError ( ) ; } catch ( err ) { const wrappedInUnknownError = wrapInUnknown ( err ) ; expect ( wrappedInUnknownError . stack ) . toContain ( 'wrapInUnknown' ) ; expect ( wrappedInUnknownError . stack ) . toContain ( '-----' ) ; expect ( wrappedInUnknownError . stack ) . toContain ( 'functionThatThrowsAnError' ) ; } } ) ; it ( 'When created with a String, UnknownError has only its own stackTrace' , ( ) => { try { functionThatThrowsAString ( ) ; } catch ( err ) { const wrappedInUnknownError = wrapInUnknown ( err ) ; expect ( wrappedInUnknownError . stack ) . toContain ( 'wrapInUnknown' ) ; expect ( wrappedInUnknownError . stack ) . not . toContain ( '-----' ) ; expect ( wrappedInUnknownError . stack ) . not . toContain ( 'functionThatThrowsAString' ) ; } } ) ; it ( 'UnknownError contains originalError' , ( ) => { try { functionThatThrowsAnError ( ) ; } catch ( err ) { const wrappedInUnknownError = wrapInUnknown ( err ) ; expect ( wrappedInUnknownError . originalError ) . toBe ( err ) ; } } ) ; it ( 'When created with an Error, UnknownError\'s message contains the original error\'s message' , ( ) => { try { functionThatThrowsAnError ( ) ; } catch ( err ) { const wrappedInUnknownError = wrapInUnknown ( err ) ; expect ( wrappedInUnknownError . message ) . toContain ( 'UnknownError' ) ; expect ( wrappedInUnknownError . message ) . toContain ( err . message ) ; } } ) ; it ( 'When created with a String, UnknownError\'s message contains the original string' , ( ) => { try { functionThatThrowsAString ( ) ; } catch ( err ) { const wrappedInUnknownError = wrapInUnknown ( err ) ; expect ( wrappedInUnknownError . message ) . toContain ( err ) ; } } ) ; } ) ;