I have written my first angular application in Angular 6
.
I have not written any test yet but there are some default test files created automatically while generating components
and services
.
When I run the auto-generated tests using
ng test
It gives too many errors. One error out of them is like
ChangeAvatarModalComponent should create
Failed: Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("
<div class="modal-body">
<form [formGroup]="changeAvatarForm" id="avatar-form" [ERROR ->]#formDir="ngForm" (submit)="onSubmit()">
<div class="row">
<div class="col-md-12">
"): ng:///DynamicTestModule/ChangeAvatarModalComponent.html@8:56
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
<div class="modal-body">
I have an account module which have ChangeAvatarModalComponent.
I have following lines inside account.module.ts
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forChild(AccountRoutes),
NgbModule
],
declarations: [
ChangeAvatarModalComponent
],
entryComponents: [
ChangeAvatarModalComponent
]
})
export class AccountModule { }
and also FormsModule
and ReactiveFormsModule
are imported in app.module.ts
There are many such errors in the log generated.
Edit 2: change-avatar-modal.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ChangeAvatarModalComponent } from './change-avatar-modal.component';
describe('ChangeAvatarModalComponent', () => {
let component: ChangeAvatarModalComponent;
let fixture: ComponentFixture<ChangeAvatarModalComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ChangeAvatarModalComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ChangeAvatarModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});