import { throwOnAnyErrors , AggregateError } from './aggregate-error' ; describe ( throwOnAnyErrors , ( ) => { it ( 'does not throw if passed zero errors' , ( ) => { expect ( ( ) => throwOnAnyErrors ( [ ] ) ) . not . toThrow ( ) ; } ) ; it ( 'rethrows the error as-is if passed one error' , ( ) => { const originalError = new Error ( 'the original error' ) ; expect ( ( ) => throwOnAnyErrors ( [ originalError ] ) ) . toThrow ( originalError ) ; } ) ; it ( 'throws an AggregateError if passed multiple errors' , ( ) => { const firstError = new Error ( 'first error' ) ; const secondError = new Error ( 'second error' ) ; try { throwOnAnyErrors ( [ firstError , secondError ] ) ; fail ( ) ; } catch ( e ) { expect ( e ) . toBeInstanceOf ( AggregateError ) ; expect ( ( e as AggregateError ) . errors ) . toStrictEqual ( [ firstError , secondError ] ) ; } } ) ; } ) ; describe ( AggregateError , ( ) => { let testSubject ; beforeEach ( ( ) => { const firstError = new Error ( 'first error' ) ; firstError . stack = `Error: first error\n    at <normalized first location>` ; const secondError = new Error ( 'second error' ) ; secondError . stack = `Error: second error\n    at <normalized second location>` ; testSubject = new AggregateError ( [ firstError , secondError ] ) ; } ) ; it ( 'uses the pinned message format' , ( ) => { expect ( testSubject . message ) . toMatchInlineSnapshot ( `
            "Multiple errors occurred
                first error
                second error"
        ` ) ; } ) ; it ( 'uses the pinned stack format' , ( ) => { const stackWithLocationsCollapsed = testSubject . stack . replace ( /^(    at) .*\n/gm , '' ) . replace ( /^(    at) .*$/gm , '$1 <normalized location>' ) ; expect ( stackWithLocationsCollapsed ) . toMatchInlineSnapshot ( `
            "AggregateError: Multiple errors occurred
                Error: first error
                    at <normalized first location>
                Error: second error
                    at <normalized second location>
                at <normalized location>"
        ` ) ; } ) ; it ( 'uses the name "AggregateError"' , ( ) => { expect ( testSubject . name ) . toBe ( 'AggregateError' ) ; } ) ; it ( 'is an Error' , ( ) => { expect ( testSubject ) . toBeInstanceOf ( Error ) ; } ) ; } ) ;