From d3e8f7a72fcc0c2e139f3b21543425ab4b31ff3f Mon Sep 17 00:00:00 2001 From: Suguru Inatomi Date: Wed, 1 Mar 2023 16:10:15 +0900 Subject: [PATCH 1/2] docs: use fine-grained overrides in examples --- apps/example-app/src/app/examples/02-input-output.spec.ts | 4 +++- projects/testing-library/src/lib/models.ts | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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 f1bd4a1c..abb71dcb 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 17974c6a..e7ba1b7a 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 + * } * } * }) */ From 5963f9f05a78bafa69910ca20f59d4b6a7d682c0 Mon Sep 17 00:00:00 2001 From: Suguru Inatomi Date: Wed, 1 Mar 2023 16:10:53 +0900 Subject: [PATCH 2/2] test: add a spec for componentOutput --- projects/testing-library/tests/render.spec.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/projects/testing-library/tests/render.spec.ts b/projects/testing-library/tests/render.spec.ts index 28e59969..2290b905 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],