2017-01-27 18 views
0

我正在與角2工作,當我運行測試與ng test --build=false --watch=false我收到此消息:納克測試「<component>是不是已知的元件」

'app-feed' is not a known element: 
1. If 'app-feed' is an Angular component, then verify that it is part of this mod 
2. If 'app-feed' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@Ng 
[ERROR ->]<app-feed></app-feed>** 

app.component.html文件內容:

<app-menu></app-menu> 
<app-feed></app-feed> 

app.component.ts文件內容:

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

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    title = 'app works!'; 
    wonderfulProperty = 'Hola'; 
} 

app.module.ts FIL E含量:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 

import { AppComponent } from './app.component'; 
import { MenuComponent } from './menu/menu.component'; 
import { FeedComponent } from './feed/feed.component'; 

@NgModule({ 
    declarations: [AppComponent,MenuComponent,FeedComponent], 
    imports: [BrowserModule, FormsModule,HttpModule], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

feed.component.ts文件內容:

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

@Component({ 
    selector: 'app-feed', 
    templateUrl: './feed.component.html', 
    styleUrls: ['./feed.component.css'] 
}) 
export class FeedComponent implements OnInit { 

    constructor() { } 

    ngOnInit() {} 

} 

有人可以幫助我弄清楚如何解決這一問題?

回答

0

如其他地方所述,您應該發佈您的spec文件。

我找到了一種方法來解決與使用模塊非常相似的問題。在feed/feed.module.ts它裏面創建一個新的模塊,並導入FeedComponent:

import {NgModule} from '@angular/core'; 
import {CommonModule} from '@angular/common'; 
import {FeedComponent} from './feed.component'; 

@ngModule({ 
    imports: [CommonModule], 
    declarations: [FeedComponent], 
    exports: [FeedComponent] 
}) 
export class FeedModule {} 

更改app.module.ts此:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { FeedModule } from './feed/feed.module'; 

import { AppComponent } from './app.component'; 
import { MenuComponent } from './menu/menu.component'; 

@NgModule({ 
    declarations: [AppComponent,MenuComponent], 
    imports: [BrowserModule, FormsModule, HttpModule, FeedModule], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

然後,包括規範文件中的進紙模塊:

import {FeedModule} from 'path/to/feed.module'; 
... 
TestBed.configureTestingModule({ 
    ... 
    imports: [FeedModule, ...] 
    ... 
}) 
相關問題