diff --git a/apps/example-app/src/app/examples/02-input-output.spec.ts b/apps/example-app/src/app/examples/02-input-output.spec.ts index f1bd4a1..abb71dc 100644 --- a/apps/example-app/src/app/examples/02-input-output.spec.ts +++ b/apps/example-app/src/app/examples/02-input-output.spec.ts @@ -6,8 +6,10 @@ test('is possible to set input and listen for output', async () => { const sendValue = jest.fn(); await render(InputOutputComponent, { - componentProperties: { + componentInputs: { value: 47, + }, + componentOutputs: { sendValue: { emit: sendValue, } as any, diff --git a/projects/testing-library/src/lib/models.ts b/projects/testing-library/src/lib/models.ts index 17974c6..e7ba1b7 100644 --- a/projects/testing-library/src/lib/models.ts +++ b/projects/testing-library/src/lib/models.ts @@ -221,9 +221,12 @@ export interface RenderComponentOptions { ... } * const component = await render(AppComponent, { * componentOutputs: { - * send: (value) => { ... } + * send: { + * emit: sendValue + * } * } * }) */ diff --git a/projects/testing-library/tests/render.spec.ts b/projects/testing-library/tests/render.spec.ts index 28e5996..2290b90 100644 --- a/projects/testing-library/tests/render.spec.ts +++ b/projects/testing-library/tests/render.spec.ts @@ -8,6 +8,8 @@ import { APP_INITIALIZER, ApplicationInitStatus, Injectable, + EventEmitter, + Output, } from '@angular/core'; import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { TestBed } from '@angular/core/testing'; @@ -155,6 +157,28 @@ describe('removeAngularAttributes', () => { }); }); +describe('componentOutputs', () => { + it('should set passed event emitter to the component', async () => { + @Component({ template: `` }) + class TestFixtureComponent { + @Output() event = new EventEmitter(); + emitEvent() { + this.event.emit(); + } + } + + const mockEmitter = new EventEmitter(); + const spy = jest.spyOn(mockEmitter, 'emit'); + const { fixture } = await render(TestFixtureComponent, { + componentOutputs: { event: mockEmitter }, + }); + + fixture.componentInstance.emitEvent(); + + expect(spy).toHaveBeenCalled(); + }); +}); + describe('animationModule', () => { @NgModule({ declarations: [FixtureComponent],