Skip to content

Commit 70b918b

Browse files
authored
docs: use fine-grained overrides in examples (#372)
* docs: use fine-grained overrides in examples * test: add a spec for componentOutput
1 parent dc4c22f commit 70b918b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

apps/example-app/src/app/examples/02-input-output.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ test('is possible to set input and listen for output', async () => {
66
const sendValue = jest.fn();
77

88
await render(InputOutputComponent, {
9-
componentProperties: {
9+
componentInputs: {
1010
value: 47,
11+
},
12+
componentOutputs: {
1113
sendValue: {
1214
emit: sendValue,
1315
} as any,

projects/testing-library/src/lib/models.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
221221
* {}
222222
*
223223
* @example
224+
* const sendValue = (value) => { ... }
224225
* const component = await render(AppComponent, {
225226
* componentOutputs: {
226-
* send: (value) => { ... }
227+
* send: {
228+
* emit: sendValue
229+
* }
227230
* }
228231
* })
229232
*/

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
APP_INITIALIZER,
99
ApplicationInitStatus,
1010
Injectable,
11+
EventEmitter,
12+
Output,
1113
} from '@angular/core';
1214
import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations';
1315
import { TestBed } from '@angular/core/testing';
@@ -155,6 +157,28 @@ describe('removeAngularAttributes', () => {
155157
});
156158
});
157159

160+
describe('componentOutputs', () => {
161+
it('should set passed event emitter to the component', async () => {
162+
@Component({ template: `` })
163+
class TestFixtureComponent {
164+
@Output() event = new EventEmitter<void>();
165+
emitEvent() {
166+
this.event.emit();
167+
}
168+
}
169+
170+
const mockEmitter = new EventEmitter<void>();
171+
const spy = jest.spyOn(mockEmitter, 'emit');
172+
const { fixture } = await render(TestFixtureComponent, {
173+
componentOutputs: { event: mockEmitter },
174+
});
175+
176+
fixture.componentInstance.emitEvent();
177+
178+
expect(spy).toHaveBeenCalled();
179+
});
180+
});
181+
158182
describe('animationModule', () => {
159183
@NgModule({
160184
declarations: [FixtureComponent],

0 commit comments

Comments
 (0)