Avi*_*Raj 10 javascript unit-testing jasmine typescript angular
我尝试测试时出现以下错误 LoginComponent
PhantomJS 2.1.1 (Linux 0.0.0): Executed 3 of 55 (1 FAILED) (0 secs / 0.307 secs)
PhantomJS 2.1.1 (Linux 0.0.0) LoginComponent should create FAILED
Failed: Uncaught (in promise): Error: Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("iv class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3">
<form (ngSubmit)="login(f)" [ERROR ->]#f="ngForm">
<div class="card card-login">
<div class="card-header text-cen"): LoginComponent@5:38
Run Code Online (Sandbox Code Playgroud)
我的组件的一部分看起来像,
login.component.ts
export class LoginComponent {
isBusy: boolean = false;
user: User;
constructor(
private router: Router,
private notificationService: NotificationService,
private authService: AuthenticationService,
private sessionService: SessionService,
) { }
....
}
Run Code Online (Sandbox Code Playgroud)
相应的规格看起来像,
login.component.spec.ts
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
let routerStub = new RouterStub();
TestBed.configureTestingModule({
imports: [HttpModule],
declarations: [,
LoginComponent
],
providers: [{
provide: Http, useFactory: (backend, options) => {
return new Http(backend, options);
},
deps: [MockBackend, BaseRequestOptions]
},
{ provide: Router, useClass: class { navigate = jasmine.createSpy("navigate"); } },
MockBackend,
BaseRequestOptions,
AuthenticationService,
SessionService,
NotificationService
],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
似乎它无法使用上面的提供程序,声明等创建假组件.像其他人说的,我已经包含FormsModule在@NgModule装饰器内部.
Gün*_*uer 21
不知道@NgModule你添加了什么装饰器,但我认为应该添加它
TestBed.configureTestingModule({
imports: [HttpModule, FormsModule],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8583 次 |
| 最近记录: |