Skip to content

docs: use fine-grained overrides in examples #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/example-app/src/app/examples/02-input-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,12 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* {}
*
* @example
* const sendValue = (value) => { ... }
* const component = await render(AppComponent, {
* componentOutputs: {
* send: (value) => { ... }
* send: {
* emit: sendValue
* }
* }
* })
*/
Expand Down
24 changes: 24 additions & 0 deletions projects/testing-library/tests/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<void>();
emitEvent() {
this.event.emit();
}
}

const mockEmitter = new EventEmitter<void>();
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],
Expand Down