200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > Angular单元测试ComponentFixture的实例化过程明细

Angular单元测试ComponentFixture的实例化过程明细

时间:2020-01-14 10:50:07

相关推荐

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的原创文章,请关注公众号"汪子熙":

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。