构造函数上的分支未涵盖 [英] Branches on constructor not covered
本文介绍了构造函数上的分支未涵盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jasmine创建单元测试,并且对覆盖的分支有疑问.
有人知道为什么代码部分显示分支没有被覆盖吗?
这是单元测试:
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
let myService: MyService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ],
imports: [ MaterializeModule, FormsModule, ReactiveFormsModule, HttpModule ],
providers: [
MyService,
FormBuilder
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
slotsService = TestBed.get(MyService);
fixture.detectChanges();
});
function updateForm(name, surname) {
component.myForm.controls['name'].setValue(name);
component.myForm.controls['surname'].setValue(name);
}
it('should create', () => {
expect(component).toBeTruthy();
});
}
解决方案
从我将项目升级到angular 4以来,几个月来我一直遇到相同的问题.不幸的是,这是angular-cli版本1和角4.
此错误已记录在 angular-cli 项目中: 解决方案
I've had the same issue for months from the moment I upgraded my projects to angular 4. Unfortunately it is a bug with the angular-cli version 1 and angular 4.
This bug is already logged in the angular-cli project: Test-coverage says that coverage is not 100%, but it truly is! #5871. Unfortunately at the moment, this issue is still open.
This is a snapshot from that logged issue, which matches the one you are asking about:
这篇关于构造函数上的分支未涵盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文