Karma 单元测试 - 找出一个组件实现了哪个抽象 class
Karma unit testing - finding out which abstract class a component implements
我对 AngularJS 和 Karma 还很陌生。尽管如此,我还是被命令编写有意义的单元测试。当我们被要求在我们创建的每个组件中实现 类 OnInit
和 OnDestroy
时,我想知道是否有一种方法可以与 Karma 检查组件是否实际实现了它们。
有人有想法吗?
为了检查实现,您将需要检查组件是否实际实现了这些抽象所需的方法 类。
如果 DummyComponent
是 implements OnInit, OnDestroy
没有其他依赖项的组件,则:
describe( 'DummyComponent', () => {
let component: DummyComponent;
beforeEach( () => {
TestBed.configureTestingModule( {
declarations: [
DummyComponent
],
providers: [
{ provide: ComponentFixtureAutoDetect, useValue: true }
]
} );
component = TestBed.createComponent( DummyComponent ).componentInstance;
} );
it( 'should implement onInit and onDestroy', () => {
expect( component.ngOnInit ).toBeDefined;
expect( component.ngOnDestroy ).toBeDefined;
} );
} );
我对 AngularJS 和 Karma 还很陌生。尽管如此,我还是被命令编写有意义的单元测试。当我们被要求在我们创建的每个组件中实现 类 OnInit
和 OnDestroy
时,我想知道是否有一种方法可以与 Karma 检查组件是否实际实现了它们。
有人有想法吗?
为了检查实现,您将需要检查组件是否实际实现了这些抽象所需的方法 类。
如果 DummyComponent
是 implements OnInit, OnDestroy
没有其他依赖项的组件,则:
describe( 'DummyComponent', () => {
let component: DummyComponent;
beforeEach( () => {
TestBed.configureTestingModule( {
declarations: [
DummyComponent
],
providers: [
{ provide: ComponentFixtureAutoDetect, useValue: true }
]
} );
component = TestBed.createComponent( DummyComponent ).componentInstance;
} );
it( 'should implement onInit and onDestroy', () => {
expect( component.ngOnInit ).toBeDefined;
expect( component.ngOnDestroy ).toBeDefined;
} );
} );