@@ -12,7 +12,9 @@ import {
12
12
Output ,
13
13
ElementRef ,
14
14
inject ,
15
+ output ,
15
16
} from '@angular/core' ;
17
+ import { outputFromObservable } from '@angular/core/rxjs-interop' ;
16
18
import { NoopAnimationsModule , BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
17
19
import { TestBed } from '@angular/core/testing' ;
18
20
import { render , fireEvent , screen } from '../src/public_api' ;
@@ -196,6 +198,11 @@ describe('subscribeToOutputs', () => {
196
198
@Output ( ) readonly event = fromEvent < MouseEvent > ( inject ( ElementRef ) . nativeElement , 'click' ) ;
197
199
}
198
200
201
+ @Component ( { template : `` , standalone : true } )
202
+ class TestFixtureWithFunctionalOutputComponent {
203
+ readonly event = output < string > ( ) ;
204
+ }
205
+
199
206
it ( 'should subscribe passed listener to the component EventEmitter' , async ( ) => {
200
207
const spy = jest . fn ( ) ;
201
208
const { fixture } = await render ( TestFixtureWithEventEmitterComponent , { subscribeToOutputs : { event : spy } } ) ;
@@ -242,14 +249,36 @@ describe('subscribeToOutputs', () => {
242
249
expect ( newSpy ) . toHaveBeenCalled ( ) ;
243
250
} ) ;
244
251
245
- it ( 'should subscribe passed listener to derived component outputs ' , async ( ) => {
252
+ it ( 'should subscribe passed listener to a derived component output ' , async ( ) => {
246
253
const spy = jest . fn ( ) ;
247
254
const { fixture } = await render ( TestFixtureWithDerivedEventComponent , {
248
255
subscribeToOutputs : { event : spy } ,
249
256
} ) ;
250
257
fireEvent . click ( fixture . nativeElement ) ;
251
258
expect ( spy ) . toHaveBeenCalled ( ) ;
252
259
} ) ;
260
+
261
+ it ( 'should subscribe passed listener to a functional component output' , async ( ) => {
262
+ const spy = jest . fn ( ) ;
263
+ const { fixture } = await render ( TestFixtureWithFunctionalOutputComponent , {
264
+ subscribeToOutputs : { event : spy } ,
265
+ } ) ;
266
+ fixture . componentInstance . event . emit ( 'test' ) ;
267
+ expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
268
+ } ) ;
269
+
270
+ 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
+ const spy = jest . fn ( ) ;
276
+ const { fixture } = await render ( TestFixtureWithFunctionalDerivedEventComponent , {
277
+ subscribeToOutputs : { event : spy } ,
278
+ } ) ;
279
+ fireEvent . click ( fixture . nativeElement ) ;
280
+ expect ( spy ) . toHaveBeenCalled ( ) ;
281
+ } ) ;
253
282
} ) ;
254
283
255
284
describe ( 'animationModule' , ( ) => {
0 commit comments