@@ -34,6 +34,15 @@ describe('disposeAll', () => {
3434 assert . deepStrictEqual ( log , [ 3 , 2 , 1 ] ) ;
3535 } ) ;
3636
37+ it ( 'should skip null or undefined items' , ( ) => {
38+ const d1 = new TestDisposable ( ) ;
39+ const d2 = new TestDisposable ( ) ;
40+ // @ts -ignore - intentional testing of invalid inputs
41+ disposeAll ( [ d1 , null , undefined , d2 ] ) ;
42+ assert . strictEqual ( d1 . disposed , true ) ;
43+ assert . strictEqual ( d2 . disposed , true ) ;
44+ } ) ;
45+
3746 it ( 'should collect errors and throw AggregateError' , ( ) => {
3847 const error1 = new Error ( 'Error 1' ) ;
3948 const error2 = new Error ( 'Error 2' ) ;
@@ -125,4 +134,25 @@ describe('Disposable', () => {
125134
126135 assert . strictEqual ( child . disposed , true ) ;
127136 } ) ;
137+
138+ it ( 'should collect errors from children and throw AggregateError on dispose' , ( ) => {
139+ const service = new MyService ( ) ;
140+ const error1 = new Error ( 'Child error 1' ) ;
141+ const error2 = new Error ( 'Child error 2' ) ;
142+ const child1 = { dispose : ( ) => { throw error1 ; } } ;
143+ const child2 = { dispose : ( ) => { throw error2 ; } } ;
144+
145+ service . register ( child1 as any ) ;
146+ service . register ( child2 as any ) ;
147+
148+ try {
149+ service . dispose ( ) ;
150+ assert . fail ( 'Should have thrown AggregateError' ) ;
151+ } catch ( err : any ) {
152+ assert . ok ( err instanceof AggregateError ) ;
153+ assert . strictEqual ( err . errors . length , 2 ) ;
154+ assert . strictEqual ( err . errors [ 0 ] , error2 ) ; // child2 disposed first (reverse order)
155+ assert . strictEqual ( err . errors [ 1 ] , error1 ) ; // child1 disposed last
156+ }
157+ } ) ;
128158} ) ;
0 commit comments