Skip to content

Commit 50e6bb8

Browse files
committed
test: add a standalone component test with child
1 parent c5f9669 commit 50e6bb8

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
import { render, screen } from "@testing-library/angular";
2-
import { StandaloneComponent } from "./19-standalone-component";
1+
import { render, screen } from '@testing-library/angular';
2+
import { StandaloneComponent, StandaloneWithChildComponent } from './19-standalone-component';
33

44
test('is possible to render a standalone component', async () => {
55
await render(StandaloneComponent);
66

77
const content = screen.getByTestId('standalone');
88

9-
expect(content).toHaveTextContent("Standalone Component")
9+
expect(content).toHaveTextContent('Standalone Component');
10+
});
11+
12+
test('is possibl to render a standalone component with a child', async () => {
13+
await render(StandaloneWithChildComponent, {
14+
componentProperties: { name: 'Bob' },
15+
});
16+
17+
const childContent = screen.getByTestId('standalone');
18+
expect(childContent).toHaveTextContent('Standalone Component');
19+
20+
expect(screen.getByText('Hi Bob')).toBeInTheDocument();
21+
expect(screen.getByText('This has a child')).toBeInTheDocument();
1022
});
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import { Component } from "@angular/core";
1+
import { Component, Input } from '@angular/core';
22

33
@Component({
44
selector: 'app-standalone',
55
template: `<div data-testid="standalone">Standalone Component</div>`,
66
standalone: true,
77
})
8-
export class StandaloneComponent {}
8+
export class StandaloneComponent { }
9+
10+
@Component({
11+
selector: 'app-standalone-with-child',
12+
template: `<h1>Hi {{ name }}</h1>
13+
<p>This has a child</p>
14+
<app-standalone></app-standalone> `,
15+
standalone: true,
16+
imports: [StandaloneComponent],
17+
})
18+
export class StandaloneWithChildComponent {
19+
@Input()
20+
name?: string;
21+
}

0 commit comments

Comments
 (0)