Przeglądałem dokumenty, sprawdzałem SO i próbowałemróżne rozwiązania / rozwiązania i po prostu nie mogę tego zrobić. Piszę test jednostkowy dla aplikacji angular4 z karmą / jaśminem. Testuje komponent, który korzysta z komponentu innej firmy ckeditor (https://www.npmjs.com/package/ng2-ckeditor). Chociaż po uruchomieniu testu pojawia się ten błąd ...
Niepowodzenie: Nieprzechwycony (w obietnicy): Błąd: Błędy analizy szablonu: „ckeditor” nie jest znanym elementem: 1. Jeśli „ckeditor” jest komponentem kątowym, sprawdź, czy jest on częścią tego modułu. 2. Aby umożliwić dowolnemu elementowi, dodaj „NO_ERRORS_SCHEMA” do „@ NgModule.schemas” tego komponentu. („[BŁĄD ->]
"): ng: /// DynamicTestModule / CkEditorComponent.HTML @ 0: 0 Błąd: Błędy analizy szablonu: „ckeditor” nie jest znanym elementem: 1. Jeśli „ckeditor” jest komponentem kątowym, sprawdź, czy jest on częścią tego modułu. 2. Aby umożliwić dowolnemu elementowi, dodaj „NO_ERRORS_SCHEMA” do „@ NgModule.schemas” tego komponentu. („[BŁĄD ->]”): ng: ///DynamicTestModule/CkEditorComponent.html@0: 0 ...
Mój plik testu jednostkowego wygląda następująco
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { ManageInvanareLoginComponent } from "./manage-invanare-login.component";
import {CreateDriftInfoComponent} from "../create-drift-info/create-drift-info.component";
import {CreateLoginTextComponent} from "../create-login-text/create-login-text.component";
import {MdInputContainer, MdInputModule} from "@angular/material";
import {CKEditorModule} from "ng2-ckeditor";
import {CkEditorComponent} from "../ck-editor/ck-editor.component";
describe("ManageInvanareLoginComponent", () => {
let component: ManageInvanareLoginComponent;
let fixture: ComponentFixture<ManageInvanareLoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
CkEditorComponent,
CreateDriftInfoComponent,
CreateLoginTextComponent,
ManageInvanareLoginComponent,
MdInputContainer
],
providers:[
CKEditorModule,
MdInputModule
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageInvanareLoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it("should create", () => {
expect(component).toBeTruthy();
});
});
Mój plik app.module.ts wygląda następująco ...
...
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { CKEditorModule } from "ng2-ckeditor";
@NgModule({ declarations: [
AppComponent,
WelcomeComponent,
DriftInfoDisplayComponent,
LoginInfoComponent,
SideBarComponent,
CkEditorComponent,
ManageInvanareLoginComponent,
CreateDriftInfoComponent,
CreateLoginTextComponent ], exports:[
CkEditorComponent ], imports: [
CKEditorModule,
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule,
BrowserAnimationsModule,
MdGridListModule,
MdButtonModule,
MdInputModule ], providers: [
PathsService,
DriftInfoDisplayComponent,
DriftInfoService
],
schemas:[NO_ERRORS_SCHEMA],
bootstrap: [AppComponent] })
export class AppModule { }
Nie chcę testować elementu ckeditor, ale chcę przetestować inne funkcje w komponencie zawierającym ten tag elementu wierzyciela.
Czy jest sposób, w jaki mogę powiedzieć testowi, aby zignorował ten tag?
Odpowiedzi:
3 dla odpowiedzi № 1Powinieneś także dodać schemas:[NO_ERRORS_SCHEMA]
do konfiguracji testowej
TestBed.configureTestingModule({
...
schemas:[NO_ERRORS_SCHEMA],
});
Zobacz też