In /src/app/book, I have the following files - book.component.ts, book.module.ts, book.component.html, book-routing.module.ts, addbook.component.html, addbook.component.ts
My book.component.html has the following codes;
<button class="btn btn-outline-success" (click)="addButton()">Add Book</button>
<div *ngIf="toggleFlag">
<app-addbook></app-addbook>
</div>
My book.module.ts has the following code:
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule,
BookRoutingModule
],
declarations: [
BookComponent,
AddbookComponent
],
providers: [BookService]
})
export class BookModule { }
My book-routing.module.ts has the below codes:
const bookRoutes: Routes = [
{
path: 'addbook',
component: AddbookComponent,
canActivate: [AuthGuardService],
}
];
@NgModule({
imports: [
RouterModule.forChild(bookRoutes)
],
exports: [
RouterModule
]
})
export class BookRoutingModule {
}
The application run well; However, when I ran the command ng test
, it show me that:
Failed: Template parse errors: 'app-addbook' is not a known element:
If 'app-addbook' is an Angular component, then verify that it is part of this module.
If 'app-addbook' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("btn btn-outline-success" (click)="addButton()">Add Book
<div *ngIf="toggleFlag">
[ERROR ->]<app-addbook></app-addbook>
</div>
UPDATE ---
My book.component.spec.ts is below:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BookComponent } from './book.component';
describe('BookComponent', () => {
let component: BookComponent;
let fixture: ComponentFixture<BookComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BookComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BookComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});