Skip to content

Commit b935d10

Browse files
author
Simon Mumenthaler
committed
add test with functional output api
1 parent c112930 commit b935d10

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

projects/testing-library/tests/render.spec.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
Output,
1313
ElementRef,
1414
inject,
15+
output,
1516
} from '@angular/core';
17+
import { outputFromObservable } from '@angular/core/rxjs-interop';
1618
import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations';
1719
import { TestBed } from '@angular/core/testing';
1820
import { render, fireEvent, screen } from '../src/public_api';
@@ -196,6 +198,11 @@ describe('subscribeToOutputs', () => {
196198
@Output() readonly event = fromEvent<MouseEvent>(inject(ElementRef).nativeElement, 'click');
197199
}
198200

201+
@Component({ template: ``, standalone: true })
202+
class TestFixtureWithFunctionalOutputComponent {
203+
readonly event = output<string>();
204+
}
205+
199206
it('should subscribe passed listener to the component EventEmitter', async () => {
200207
const spy = jest.fn();
201208
const { fixture } = await render(TestFixtureWithEventEmitterComponent, { subscribeToOutputs: { event: spy } });
@@ -242,14 +249,36 @@ describe('subscribeToOutputs', () => {
242249
expect(newSpy).toHaveBeenCalled();
243250
});
244251

245-
it('should subscribe passed listener to derived component outputs', async () => {
252+
it('should subscribe passed listener to a derived component output', async () => {
246253
const spy = jest.fn();
247254
const { fixture } = await render(TestFixtureWithDerivedEventComponent, {
248255
subscribeToOutputs: { event: spy },
249256
});
250257
fireEvent.click(fixture.nativeElement);
251258
expect(spy).toHaveBeenCalled();
252259
});
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+
});
253282
});
254283

255284
describe('animationModule', () => {

0 commit comments

Comments
 (0)