Angular单元测试ComponentFixture的实例化过程明细
生活随笔
收集整理的這篇文章主要介紹了
Angular单元测试ComponentFixture的实例化过程明细
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
從angular core里導入單元測試需要的庫文件:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';定義一個fixture:
let fixture: ComponentFixture;
fixture的實例化方法:
beforeEach(() => {fixture = TestBed.createComponent(ProductCarouselComponent);fixture.detectChanges();});觀察其實例化過程:
使用testBedRender3創建Component:
type就是ProductCarouselComponent的構造函數:
使用Componentfactory創建實例:
拿到Component selector的值:
最后創建好的fixture如下:
其Componentinstance屬性存放的就是ProductCarouselComponent的實例:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的Angular单元测试ComponentFixture的实例化过程明细的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在Chrome调试器里检查嵌套Obs
- 下一篇: SAP Spartacus应用启用时导入