Skip to content

Commit 6973366

Browse files
committed
fix: allow input properties to be aliased
1 parent 20a7e6a commit 6973366

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
196196
* }
197197
* })
198198
*/
199-
componentInputs?: Partial<ComponentType>;
199+
componentInputs?: Partial<ComponentType> | { [key: string]: unknown };
200200
/**
201201
* @description
202202
* An object to set `@Output` properties of the component

projects/testing-library/tests/issues/issue-386.spec.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import {Component} from '@angular/core';
2-
import {throwError} from 'rxjs';
3-
import {render, screen} from '@testing-library/angular';
1+
import { Component } from '@angular/core';
2+
import { throwError } from 'rxjs';
43
import userEvent from '@testing-library/user-event';
4+
import { render, screen } from '../../src/public_api';
55

66
@Component({
7-
selector: 'app-test',
7+
selector: 'atl-fixture',
88
template: `<button (click)="onTest()">Test</button>`,
99
styles: [],
1010
})
11-
export class TestComponent {
11+
class TestComponent {
1212
onTest() {
1313
throwError(() => new Error('myerror')).subscribe();
1414
}
1515
}
1616

17-
1817
describe('TestComponent', () => {
1918
beforeEach(() => {
2019
jest.useFakeTimers();
@@ -23,7 +22,7 @@ describe('TestComponent', () => {
2322
afterEach(() => {
2423
jest.runAllTicks();
2524
jest.useRealTimers();
26-
})
25+
});
2726

2827
it('does not fail', async () => {
2928
await render(TestComponent);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, Input } from '@angular/core';
2+
import { render, screen } from '../../src/public_api';
3+
4+
@Component({
5+
selector: 'atl-fixture',
6+
template: `Hello {{ name }}`,
7+
})
8+
class TestComponent {
9+
// eslint-disable-next-line @angular-eslint/no-input-rename
10+
@Input('aliasName') name = '';
11+
}
12+
13+
test('allows you to set componentInputs using the name alias', async () => {
14+
await render(TestComponent, { componentInputs: { aliasName: 'test' } });
15+
expect(screen.getByText('Hello test')).toBeInTheDocument();
16+
});

0 commit comments

Comments
 (0)