@@ -17,7 +17,7 @@ import {
17
17
import { outputFromObservable } from '@angular/core/rxjs-interop' ;
18
18
import { NoopAnimationsModule , BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
19
19
import { TestBed } from '@angular/core/testing' ;
20
- import { render , fireEvent , screen } from '../src/public_api' ;
20
+ import { render , fireEvent , screen , OutputRefKeysWithCallback } from '../src/public_api' ;
21
21
import { ActivatedRoute , Resolve , RouterModule } from '@angular/router' ;
22
22
import { fromEvent , map } from 'rxjs' ;
23
23
import { AsyncPipe , NgIf } from '@angular/common' ;
@@ -203,6 +203,11 @@ describe('on', () => {
203
203
readonly event = output < string > ( ) ;
204
204
}
205
205
206
+ @Component ( { template : `` , standalone : true } )
207
+ class TestFixtureWithFunctionalDerivedEventComponent {
208
+ readonly event = outputFromObservable ( fromEvent < MouseEvent > ( inject ( ElementRef ) . nativeElement , 'click' ) ) ;
209
+ }
210
+
206
211
it ( 'should subscribe passed listener to the component EventEmitter' , async ( ) => {
207
212
const spy = jest . fn ( ) ;
208
213
const { fixture } = await render ( TestFixtureWithEventEmitterComponent , { on : { event : spy } } ) ;
@@ -268,17 +273,42 @@ describe('on', () => {
268
273
} ) ;
269
274
270
275
it ( 'should subscribe passed listener to a functional derived component output' , async ( ) => {
271
- @Component ( { template : `` , standalone : true } )
272
- class TestFixtureWithFunctionalDerivedEventComponent {
273
- readonly event = outputFromObservable ( fromEvent < MouseEvent > ( inject ( ElementRef ) . nativeElement , 'click' ) ) ;
274
- }
275
276
const spy = jest . fn ( ) ;
276
277
const { fixture } = await render ( TestFixtureWithFunctionalDerivedEventComponent , {
277
278
on : { event : spy } ,
278
279
} ) ;
279
280
fireEvent . click ( fixture . nativeElement ) ;
280
281
expect ( spy ) . toHaveBeenCalled ( ) ;
281
282
} ) ;
283
+
284
+ it ( 'OutputRefKeysWithCallback is correctly typed' , ( ) => {
285
+ const fnWithVoidArg = ( _ : void ) => void 0 ;
286
+ const fnWithNumberArg = ( _ : number ) => void 0 ;
287
+ const fnWithStringArg = ( _ : string ) => void 0 ;
288
+ const fnWithMouseEventArg = ( _ : MouseEvent ) => void 0 ;
289
+
290
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
291
+ function _test < T > ( _on : OutputRefKeysWithCallback < T > ) { }
292
+
293
+ // @ts -expect-error
294
+ _test < TestFixtureWithEventEmitterComponent > ( { event : fnWithNumberArg } ) ;
295
+ _test < TestFixtureWithEventEmitterComponent > ( { event : fnWithVoidArg } ) ;
296
+
297
+ // @ts -expect-error
298
+ _test < TestFixtureWithDerivedEventComponent > ( { event : fnWithNumberArg } ) ;
299
+ _test < TestFixtureWithDerivedEventComponent > ( { event : fnWithMouseEventArg } ) ;
300
+
301
+ // @ts -expect-error
302
+ _test < TestFixtureWithFunctionalOutputComponent > ( { event : fnWithNumberArg } ) ;
303
+ _test < TestFixtureWithFunctionalOutputComponent > ( { event : fnWithStringArg } ) ;
304
+
305
+ // @ts -expect-error
306
+ _test < TestFixtureWithFunctionalDerivedEventComponent > ( { event : fnWithNumberArg } ) ;
307
+ _test < TestFixtureWithFunctionalDerivedEventComponent > ( { event : fnWithMouseEventArg } ) ;
308
+
309
+ // add a statement so the test succeeds
310
+ expect ( true ) . toBeTruthy ( ) ;
311
+ } ) ;
282
312
} ) ;
283
313
284
314
describe ( 'animationModule' , ( ) => {
0 commit comments