@@ -24,27 +24,12 @@ export async function createComponent<T>(
2424 schemas : [ ...schemas ] ,
2525 } ) ;
2626
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 ) ;
3430
3531 await TestBed . compileComponents ( ) ;
3632
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-
4833 if ( detectChanges ) {
4934 fixture . detectChanges ( ) ;
5035 }
@@ -63,3 +48,21 @@ export async function createComponent<T>(
6348 ...getQueriesForElement ( fixture . nativeElement ) ,
6449 } ;
6550}
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