Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a9f0065

Browse files
flakolefluktimdeschryver
authored andcommitted
feat: use render without render options (testing-library#21)
1 parent 7c8f02a commit a9f0065

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ class WrapperComponent implements OnInit {
1313
}
1414
}
1515

16+
export async function render<T>(template: string, renderOptions: RenderOptions<T>);
17+
export async function render<T>(component: Type<T>, renderOptions?: RenderOptions<T>);
1618
export async function render<T>(
1719
templateOrComponent: string | Type<T>,
18-
{
20+
renderOptions: RenderOptions<T> = {},
21+
): Promise<RenderResult> {
22+
const {
1923
detectChanges = true,
2024
declarations = [],
2125
imports = [],
@@ -24,8 +28,8 @@ export async function render<T>(
2428
queries,
2529
wrapper = WrapperComponent,
2630
componentProperties = {},
27-
}: RenderOptions<T>,
28-
): Promise<RenderResult>{
31+
}=renderOptions;
32+
2933
const isTemplate = typeof templateOrComponent === 'string';
3034
const componentDeclarations = isTemplate ? [wrapper] : [templateOrComponent];
3135

‎projects/testing-library/tests/counter/counter.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ test('Counter actions via component syntax', async () => {
6565
expect(getByTestId('count').textContent).toBe('Current Count: 0');
6666
});
6767

68+
test('Counter actions via component syntax without render options', async () => {
69+
const { getByText, getByTestId, click } = await render(CounterComponent);
70+
71+
click(getByText('+'));
72+
expect(getByText('Current Count: 1')).toBeTruthy();
73+
expect(getByTestId('count').textContent).toBe('Current Count: 1');
74+
75+
click(getByText('-'));
76+
expect(getByText('Current Count: 0')).toBeTruthy();
77+
expect(getByTestId('count').textContent).toBe('Current Count: 0');
78+
});
79+
6880
test('Counter actions via component syntax with parameters', async () => {
6981
const { getByText, getByTestId, click } = await render(CounterComponent, {
7082
declarations: [CounterComponent],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /