[英]Angular Unit Testing : How to run a basic Test
Am new on angular unit testing. 是角单元测试的新功能。
I wanna implement a first running test so i developed this : 我想执行首次运行测试,所以我开发了这个:
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');
});
});
Like you see my first test is to assert that "1" is "1" , i don't know why i'm facing a problem of getting it successfull , since it throws me such an error : 就像您看到的那样,我的第一个测试是断言“ 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
It's true that i'm using DevExtreme widgets in my app component , but i haven't even tried to test it. 的确,我在我的应用程序组件中使用了DevExtreme小部件,但我什至没有尝试对其进行测试。 i'm just starting by evident test cases.
我只是从明显的测试用例开始。
I need to know how should i fix it? 我需要知道该如何解决?
Suggestions ?? 建议??
You have to include all things that need to compile your component in your TestBed.configureTestingModule
: 您必须在
TestBed.configureTestingModule
包括所有需要编译组件的TestBed.configureTestingModule
:
// import { DevExtremeModule } from 'devextreme-angular';
import { DxProgressBarModule } from 'devextreme-angular/ui/progress-bar';
TestBed.configureTestingModule({
imports: [
DxProgressBarModule,
// or DevExtremeModule
],
declarations: [ AppComponent ],
}).compileComponents();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.