Angular 单元测试:如何 运行 进行基本测试
Angular Unit Testing : How to run a basic Test
我是 angular 单元测试的新手。
我想实施第一个 运行 测试,所以我开发了这个:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('first test', () => {
expect('1').toBe('1');
});
});
就像你看到的那样,我的第一个测试是断言“1”是“1”,我不知道为什么我会遇到成功获取它的问题,因为它会抛出这样的错误:
Error: Template parse errors: Can't bind to 'min' since it isn't a known property of 'dx-progress-bar'.
1. If 'dx-progress-bar' is an Angular component and it has 'min' input, then verify that it is part of this module.
2. If 'dx-progress-bar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
width="100%"
[class.complete]="progressBar.value == maxValue"
[ERROR ->][min]="0"
[max]="maxValue"
[statusFormat]="wordProgression" "): ng:///DynamicTestModule/AppComponent.html@15:4
我确实在我的应用程序组件中使用了 DevExtreme 小部件,但我什至没有尝试对其进行测试。我只是从明显的测试用例开始。
我需要知道我该如何修复它?
建议??
您必须在 TestBed.configureTestingModule
:
中包含编译组件所需的所有内容
// import { DevExtremeModule } from 'devextreme-angular';
import { DxProgressBarModule } from 'devextreme-angular/ui/progress-bar';
TestBed.configureTestingModule({
imports: [
DxProgressBarModule,
// or DevExtremeModule
],
declarations: [ AppComponent ],
}).compileComponents();
我是 angular 单元测试的新手。
我想实施第一个 运行 测试,所以我开发了这个:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('first test', () => {
expect('1').toBe('1');
});
});
就像你看到的那样,我的第一个测试是断言“1”是“1”,我不知道为什么我会遇到成功获取它的问题,因为它会抛出这样的错误:
Error: Template parse errors: Can't bind to 'min' since it isn't a known property of 'dx-progress-bar'.
1. If 'dx-progress-bar' is an Angular component and it has 'min' input, then verify that it is part of this module.
2. If 'dx-progress-bar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
width="100%"
[class.complete]="progressBar.value == maxValue"
[ERROR ->][min]="0"
[max]="maxValue"
[statusFormat]="wordProgression" "): ng:///DynamicTestModule/AppComponent.html@15:4
我确实在我的应用程序组件中使用了 DevExtreme 小部件,但我什至没有尝试对其进行测试。我只是从明显的测试用例开始。
我需要知道我该如何修复它?
建议??
您必须在 TestBed.configureTestingModule
:
// import { DevExtremeModule } from 'devextreme-angular';
import { DxProgressBarModule } from 'devextreme-angular/ui/progress-bar';
TestBed.configureTestingModule({
imports: [
DxProgressBarModule,
// or DevExtremeModule
],
declarations: [ AppComponent ],
}).compileComponents();