@@ -24,27 +24,12 @@ export async function createComponent<T>(
24
24
schemas : [ ...schemas ] ,
25
25
} ) ;
26
26
27
- if ( isTemplate ) {
28
- TestBed . overrideComponent ( TestComponent , {
29
- set : {
30
- template : < string > templateOrComponent ,
31
- } ,
32
- } ) ;
33
- }
27
+ const fixture = isTemplate
28
+ ? createTestComponentFixture ( < string > templateOrComponent )
29
+ : createComponentFixture ( < ComponentInput < T > > templateOrComponent ) ;
34
30
35
31
await TestBed . compileComponents ( ) ;
36
32
37
- let fixture ;
38
- if ( isTemplate ) {
39
- fixture = TestBed . createComponent ( TestComponent ) ;
40
- } else {
41
- const { component, parameters = [ ] } = < ComponentInput < T > > templateOrComponent ;
42
- fixture = TestBed . createComponent ( component ) ;
43
- for ( const key of Object . keys ( parameters ) ) {
44
- fixture . componentInstance [ key ] = parameters [ key ] ;
45
- }
46
- }
47
-
48
33
if ( detectChanges ) {
49
34
fixture . detectChanges ( ) ;
50
35
}
@@ -63,3 +48,21 @@ export async function createComponent<T>(
63
48
...getQueriesForElement ( fixture . nativeElement ) ,
64
49
} ;
65
50
}
51
+
52
+ function createTestComponentFixture ( template : string ) {
53
+ TestBed . overrideComponent ( TestComponent , {
54
+ set : {
55
+ template : template ,
56
+ } ,
57
+ } ) ;
58
+ return TestBed . createComponent ( TestComponent ) ;
59
+ }
60
+
61
+ function createComponentFixture < T > ( componentInput : ComponentInput < T > ) {
62
+ const { component, parameters = { } } = componentInput ;
63
+ const fixture = TestBed . createComponent ( component ) ;
64
+ for ( const key of Object . keys ( parameters ) ) {
65
+ fixture . componentInstance [ key ] = parameters [ key ] ;
66
+ }
67
+ return fixture ;
68
+ }
0 commit comments