Skip to content

Commit

Permalink
feat: use render without render options (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
flakolefluk authored and timdeschryver committed Jun 11, 2019
1 parent 7c8f02a commit a9f0065
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ class WrapperComponent implements OnInit {
}
}

export async function render<T>(template: string, renderOptions: RenderOptions<T>);
export async function render<T>(component: Type<T>, renderOptions?: RenderOptions<T>);
export async function render<T>(
templateOrComponent: string | Type<T>,
{
renderOptions: RenderOptions<T> = {},
): Promise<RenderResult> {
const {
detectChanges = true,
declarations = [],
imports = [],
Expand All @@ -24,8 +28,8 @@ export async function render<T>(
queries,
wrapper = WrapperComponent,
componentProperties = {},
}: RenderOptions<T>,
): Promise<RenderResult> {
} = renderOptions;

const isTemplate = typeof templateOrComponent === 'string';
const componentDeclarations = isTemplate ? [wrapper] : [templateOrComponent];

Expand Down
12 changes: 12 additions & 0 deletions projects/testing-library/tests/counter/counter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ test('Counter actions via component syntax', async () => {
expect(getByTestId('count').textContent).toBe('Current Count: 0');
});

test('Counter actions via component syntax without render options', async () => {
const { getByText, getByTestId, click } = await render(CounterComponent);

click(getByText('+'));
expect(getByText('Current Count: 1')).toBeTruthy();
expect(getByTestId('count').textContent).toBe('Current Count: 1');

click(getByText('-'));
expect(getByText('Current Count: 0')).toBeTruthy();
expect(getByTestId('count').textContent).toBe('Current Count: 0');
});

test('Counter actions via component syntax with parameters', async () => {
const { getByText, getByTestId, click } = await render(CounterComponent, {
declarations: [CounterComponent],
Expand Down

0 comments on commit a9f0065

Please sign in to comment.