@@ -1657,6 +1657,87 @@ describe('TestBed', () => {
1657
1657
return ComponentClass ;
1658
1658
} ;
1659
1659
1660
+ it ( 'should not require compileComponent if the component is not overridden' , async ( ) => {
1661
+ const RootAotComponent = getAOTCompiledComponent ( 'root' , [ ] , [ ] ) ;
1662
+
1663
+ TestBed . configureTestingModule ( { imports : [ RootAotComponent ] } ) ;
1664
+
1665
+ // If we had overriden the component, we would need to compile it
1666
+ // but since we didn't, we can create the component synchronously
1667
+ const fixture = TestBed . createComponent ( RootAotComponent ) ;
1668
+ fixture . detectChanges ( ) ;
1669
+
1670
+ expect ( fixture . nativeElement . textContent ) . toBe ( 'root cmp!' ) ;
1671
+ } ) ;
1672
+
1673
+ it ( 'should throw an error if a deferred component is not compiled' , ( ) => {
1674
+ @Component ( {
1675
+ selector : 'cmp-a' ,
1676
+ template : 'CmpA!' ,
1677
+ } )
1678
+ class CmpA { }
1679
+
1680
+ const NestedAotComponent = getAOTCompiledComponent ( 'nested-cmp' , [ ] , [ CmpA ] ) ;
1681
+ const RootAotComponent = getAOTCompiledComponent ( 'root' , [ ] , [ NestedAotComponent ] ) ;
1682
+
1683
+ TestBed . configureTestingModule ( { imports : [ RootAotComponent ] } ) ;
1684
+
1685
+ TestBed . overrideComponent ( RootAotComponent , {
1686
+ set : { template : `Override of a root template! <nested-cmp />` } ,
1687
+ } ) ;
1688
+ TestBed . overrideComponent ( NestedAotComponent , {
1689
+ set : { template : `Override of a nested template! <cmp-a />` } ,
1690
+ } ) ;
1691
+
1692
+ // We did override but not compile, therefore we expect to throw on createComponent
1693
+ expect ( ( ) => TestBed . createComponent ( RootAotComponent ) ) . toThrowError (
1694
+ `Component 'ComponentClass' has unresolved metadata. Please call \`await TestBed.compileComponents()\` before running this test.` ,
1695
+ ) ;
1696
+ } ) ;
1697
+
1698
+ it ( 'should not throw if component is created after override+reset' , async ( ) => {
1699
+ @Component ( {
1700
+ selector : 'cmp-a' ,
1701
+ template : 'CmpA!' ,
1702
+ } )
1703
+ class CmpA { }
1704
+
1705
+ const NestedAotComponent = getAOTCompiledComponent ( 'nested-cmp' , [ ] , [ CmpA ] ) ;
1706
+ const RootAotComponent = getAOTCompiledComponent ( 'root' , [ ] , [ NestedAotComponent ] ) ;
1707
+
1708
+ TestBed . configureTestingModule ( { imports : [ RootAotComponent ] } ) ;
1709
+
1710
+ TestBed . overrideComponent ( RootAotComponent , {
1711
+ set : { template : `Override of a root template! <nested-cmp />` } ,
1712
+ } ) ;
1713
+ TestBed . overrideComponent ( NestedAotComponent , {
1714
+ set : { template : `Override of a nested template! <cmp-a />` } ,
1715
+ } ) ;
1716
+
1717
+ // Not compiled yet, so we expect to throw
1718
+ expect ( ( ) => TestBed . createComponent ( RootAotComponent ) ) . toThrowError ( ) ;
1719
+
1720
+ await TestBed . compileComponents ( ) ;
1721
+
1722
+ // We're compiled now, so we can create the component
1723
+ const fixture = TestBed . createComponent ( RootAotComponent ) ;
1724
+ fixture . detectChanges ( ) ;
1725
+
1726
+ expect ( fixture . nativeElement . textContent ) . toBe (
1727
+ 'Override of a root template! Override of a nested template! CmpA!' ,
1728
+ ) ;
1729
+
1730
+ // We reset the override
1731
+ TestBed . resetTestingModule ( ) ;
1732
+ TestBed . configureTestingModule ( { imports : [ RootAotComponent ] } ) ;
1733
+
1734
+ // We're back to the nominal behavior
1735
+ const fixture2 = TestBed . createComponent ( RootAotComponent ) ;
1736
+ fixture2 . detectChanges ( ) ;
1737
+
1738
+ expect ( fixture2 . nativeElement . textContent ) . toBe ( 'root cmp!' ) ;
1739
+ } ) ;
1740
+
1660
1741
it ( 'should handle async metadata on root and nested components' , async ( ) => {
1661
1742
@Component ( {
1662
1743
selector : 'cmp-a' ,
0 commit comments