Skip to content

fix: allow input properties to be aliased #391

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 1 commit into from
May 29, 2023
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
2 changes: 1 addition & 1 deletion projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* }
* })
*/
componentInputs?: Partial<ComponentType>;
componentInputs?: Partial<ComponentType> | { [alias: string]: unknown };
/**
* @description
* An object to set `@Output` properties of the component
Expand Down
13 changes: 6 additions & 7 deletions projects/testing-library/tests/issues/issue-386.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import {Component} from '@angular/core';
import {throwError} from 'rxjs';
import {render, screen} from '@testing-library/angular';
import { Component } from '@angular/core';
import { throwError } from 'rxjs';
import userEvent from '@testing-library/user-event';
import { render, screen } from '../../src/public_api';

@Component({
selector: 'app-test',
selector: 'atl-fixture',
template: `<button (click)="onTest()">Test</button>`,
styles: [],
})
export class TestComponent {
class TestComponent {
onTest() {
throwError(() => new Error('myerror')).subscribe();
}
}


describe('TestComponent', () => {
beforeEach(() => {
jest.useFakeTimers();
Expand All @@ -23,7 +22,7 @@ describe('TestComponent', () => {
afterEach(() => {
jest.runAllTicks();
jest.useRealTimers();
})
});

it('does not fail', async () => {
await render(TestComponent);
Expand Down
16 changes: 16 additions & 0 deletions projects/testing-library/tests/issues/issue-389.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, Input } from '@angular/core';
import { render, screen } from '../../src/public_api';

@Component({
selector: 'atl-fixture',
template: `Hello {{ name }}`,
})
class TestComponent {
// eslint-disable-next-line @angular-eslint/no-input-rename
@Input('aliasName') name = '';
}

test('allows you to set componentInputs using the name alias', async () => {
await render(TestComponent, { componentInputs: { aliasName: 'test' } });
expect(screen.getByText('Hello test')).toBeInTheDocument();
});