Skip to content

Commit 9cd8e91

Browse files
committed
feat: no need to pass the component as declaration with the component syntax
1 parent 32a552a commit 9cd8e91

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface RenderResult extends RenderResultQueries, FireObject {
1212

1313
export interface RenderOptions<C, Q extends Queries = typeof queries> {
1414
detectChanges?: boolean;
15-
declarations: any[];
15+
declarations?: any[];
1616
providers?: any[];
1717
imports?: any[];
1818
schemas?: any[];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export async function render<T>(
2828
}: RenderOptions<T>,
2929
): Promise<RenderResult> {
3030
const isTemplate = typeof templateOrComponent === 'string';
31-
const testComponent = isTemplate ? [wrapper] : [];
31+
const componentDeclarations = isTemplate ? [wrapper] : [templateOrComponent];
3232

3333
TestBed.configureTestingModule({
34-
declarations: [...declarations, ...testComponent],
34+
declarations: [...declarations, ...componentDeclarations],
3535
providers: [...providers],
3636
imports: [...imports],
3737
schemas: [...schemas],

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ test('Counter actions via template syntax with parameters', async () => {
5151
});
5252

5353
test('Counter actions via component syntax', async () => {
54+
const { getByText, getByTestId, click } = await render(CounterComponent, {
55+
declarations: [CounterComponent],
56+
});
57+
58+
click(getByText('+'));
59+
expect(getByText('Current Count: 1')).toBeTruthy();
60+
expect(getByTestId('count').textContent).toBe('Current Count: 1');
61+
62+
click(getByText('-'));
63+
expect(getByText('Current Count: 0')).toBeTruthy();
64+
expect(getByTestId('count').textContent).toBe('Current Count: 0');
65+
});
66+
67+
test('Counter actions via component syntax with parameters', async () => {
5468
const { getByText, getByTestId, click } = await render(CounterComponent, {
5569
declarations: [CounterComponent],
5670
componentProperties: {
@@ -67,16 +81,18 @@ test('Counter actions via component syntax', async () => {
6781
expect(getByTestId('count').textContent).toBe('Current Count: 10');
6882
});
6983

70-
test('Counter actions via component syntax without parameters', async () => {
84+
test('Counter actions via component syntax without declaration', async () => {
7185
const { getByText, getByTestId, click } = await render(CounterComponent, {
72-
declarations: [CounterComponent],
86+
componentProperties: {
87+
counter: 10,
88+
},
7389
});
7490

7591
click(getByText('+'));
76-
expect(getByText('Current Count: 1')).toBeTruthy();
77-
expect(getByTestId('count').textContent).toBe('Current Count: 1');
92+
expect(getByText('Current Count: 11')).toBeTruthy();
93+
expect(getByTestId('count').textContent).toBe('Current Count: 11');
7894

7995
click(getByText('-'));
80-
expect(getByText('Current Count: 0')).toBeTruthy();
81-
expect(getByTestId('count').textContent).toBe('Current Count: 0');
96+
expect(getByText('Current Count: 10')).toBeTruthy();
97+
expect(getByTestId('count').textContent).toBe('Current Count: 10');
8298
});

0 commit comments

Comments
 (0)