2017-07-02 2 views
0

私は角を覚えています。私の最初のカルマテストでは以下のエラーがスローされます。角カルマテストに失敗しました。カスタムタグはノウズ要素ではありません。

AppComponent should create component 
Error: Template parse errors: 
'ereturn-form' is not a known element: 
1. If 'ereturn-form' is an Angular component, then verify that it is part of this module. 
2. If 'ereturn-form' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<ereturn-form></ereturn-form>"): ng:///DynamicTestModule/[email protected]:0 

これは

app.module.ts

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { ReactiveFormsModule } from '@angular/forms'; 
import { HttpModule, JsonpModule } from '@angular/http'; 
import { EreturnService } from './ereturn.service'; 

import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; 
import { InMemoryDataService } from './in-memory-data.service'; 

import { AppComponent }   from './app.component'; 
import { EreturnFormComponent} from './ereturn-form.component'; 

@NgModule({ 
    imports:  [ BrowserModule, ReactiveFormsModule, HttpModule, JsonpModule, 
    InMemoryWebApiModule.forRoot(InMemoryDataService)], 
    declarations: [ AppComponent, EreturnFormComponent ], 
    bootstrap: [ AppComponent ], 
    providers: [ EreturnService ] 
}) 

export class AppModule { } 

app.component.ts

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: '<ereturn-form></ereturn-form>', 
}) 
export class AppComponent { } 

ereturn-form.component.ts

私のモジュールやコンポーネントです
import { Component, OnInit, Input, OnChanges } from '@angular/core'; 

import { Ereturn } from './ereturn'; 
import { EreturnService } from './ereturn.service'; 
import { FormBuilder, FormGroup, Validators } from "@angular/forms"; 

@Component({ 
    selector: 'ereturn-form', 
    templateUrl: './ereturn-form.component.html' 
}) 

export class EreturnFormComponent implements OnInit { 
... 
} 

これはカルマがカスタムHTMLタグ文句を言っているのはなぜ私のスペックは

describe('1st tests',() => { 
    it('true is true',() => expect(true).toBe(true)); 
}); 

を提出ですか?角をコンパイルし、それを正常に実行します。

は、あなたの要素は、カスタム・コンポーネントである場合は、宣言の一部として、あなたのテストにそれを追加する必要があり、非常に

+0

?投稿を更新する – Aravind

+0

ありがとう@Aravind、私は仕様ファイルを追加しました –

+0

1行では不十分です。スペック・ファイルのモジュール作成で間違っていたかもしれない完全なスペック・ファイルを追加してください。 – Aravind

答えて

1

をお願いします。

import { CustomElement } from '...your path here'; 
 

 
describe('AppComponent',() => { 
 
    beforeEach(() => { 
 
    TestBed.configureTestingModule({ 
 
     schemas: [ ], 
 
     declarations: [CustomElement], 
 
     imports: [RouterTestingModule] 
 
    }); 
 
    TestBed.compileComponents(); 
 
    });

あなたがその特定の要素を無視したい場合は、スキーマの配列にCUSTOM_ELEMENTS_SCHEMAを追加することによって、それを無視することができます

beforeEach(() => { 
 
    TestBed.configureTestingModule({ 
 
     schemas: [ CUSTOM_ELEMENTS_SCHEMA ], 
 
     declarations: [], 
 
     imports: [] 
 
    });

そして最後に、それが別のライブラリから来た場合は、それを追加する必要がありますテストへのモジュール:

specファイルのコードがある

import { CustomeModule } from 'module name here'; 
 

 
describe('AppComponent',() => { 
 
    beforeEach(() => { 
 
    TestBed.configureTestingModule({ 
 
     schemas: [ ], 
 
     declarations: [], 
 
     imports: [CustomeModule] 
 
    }); 
 
    TestBed.compileComponents(); 
 
    });

関連する問題