2016-11-29 10 views
0

私は角度2のコンポーネントをテストしようとしていますが、依存関係の読み込みに問題があります。角2のテストの依存関係

をテストするときにUserModuleをインポートしようとするとカルマエラーが発生します。インポートしないとコンポーネントエラーが多く発生します。

テスト・セットアップは、角度-CLIが発生するもので、私の特定のテストには、以下の

import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 
import { By } from '@angular/platform-browser'; 
import { DebugElement } from '@angular/core'; 

import { UserModule } from '../../user.module'; 
import { UserShowcaseComponent } from './user-showcase.component'; 

describe('UserShowcaseComponent',() => { 
    let component: UserShowcaseComponent; 
    let fixture: ComponentFixture<UserShowcaseComponent>; 

    beforeEach(async(() => { 
     TestBed.configureTestingModule({ 
      imports: [UserModule],  <---------------------------------- NOTE 
     }) 
      .compileComponents(); 
    })); 

    beforeEach(() => { 
     fixture = TestBed.createComponent(UserShowcaseComponent); 
     component = fixture.componentInstance; 
     fixture.detectChanges(); 
    }); 

    it('should create',() => { 
     expect(component).toBeTruthy(); 
    }); 
}); 

あるカルマからエラーが単にこの(これはフル出力で、何のテストが実行されていない)である。

29 11 2016 16:49:40.478:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/ 
29 11 2016 16:49:40.479:INFO [launcher]: Launching browser Chrome with unlimited concurrency 
29 11 2016 16:49:40.649:INFO [launcher]: Starting browser Chrome 
29 11 2016 16:49:42.010:INFO [Chrome 53.0.2785 (Linux 0.0.0)]: Connected on socket /#Jpv1IioGnou6CQtUAAAA with id 98117142 
Chrome 53.0.2785 (Linux 0.0.0) ERROR 

答えて

0

カルマがベンダーファイルを読み込んでいないという問題がありましたが、これは正しく報告されていませんでした。この報告の問題は、angular-cli 1.0.0-beta.20として修正されました。this commitを参照してください。

ソリューションはfiles

{ pattern: './node_modules/jquery/dist/jquery.min.js', watched: false } 

を追加私の場合には、karma.conf.jsでベンダーLIBSを追加することです。

はい、私はjqueryを使用すべきではないことを知っています。

関連する問題