File tree 2 files changed +30
-5
lines changed
apps/example-app/src/app/examples
2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 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' ;
3
3
4
4
test ( 'is possible to render a standalone component' , async ( ) => {
5
5
await render ( StandaloneComponent ) ;
6
6
7
7
const content = screen . getByTestId ( 'standalone' ) ;
8
8
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 ( ) ;
10
22
} ) ;
Original file line number Diff line number Diff line change 1
- import { Component } from " @angular/core" ;
1
+ import { Component , Input } from ' @angular/core' ;
2
2
3
3
@Component ( {
4
4
selector : 'app-standalone' ,
5
5
template : `<div data-testid="standalone">Standalone Component</div>` ,
6
6
standalone : true ,
7
7
} )
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
+ }
You can’t perform that action at this time.
0 commit comments