2017-08-09 137 views
0

我正在使用angular2和uirouter進行路由。我在應用程序中成功實現了uirouter模塊。但是當我嘗試測試我的應用程序時出現問題。我在哪裏使用業力,茉莉和啓動它使用npm test。但遇到ERROR:Can't resolve all parameters for UIRouter: (?, ?).無法解析UIRouter的所有參數:(?,?)

我已經在*.spec.ts文件中導入了「UIRouter」,並將其添加到providers數組中,如下所示。

import { UIRouterModule } from '@uirouter/angular'; 
import { UIRouter } from "@uirouter/core"; 
describe('Footer Menus',() => { 
    let footerMenuBlServiceRef:FooterMenuBLService; 
    beforeEach(async(() => { 
    TestBed.configureTestingModule({ 
     imports: [], 
     declarations: [], 
     providers: [UIRouter], 
    }) 
     .compileComponents(); 
    })); 

但沒有運氣。任何幫助將不勝感激。

回答

0

解決了! 只需從providers數組中刪除UIRouter但保留import語句。是的,它的工作。

+0

嗨!你能否提供更多關於你的決議的細節? 我有同樣的問題,你的回答並沒有幫助我解決我的問題。 我在我的模塊中有UIRouterModule.forChild,我不知道如何在spec文件中模擬它。感謝您的幫助:) – Pitchou

+0

嘿Pitchou,你可以添加你的規範文件代碼,以更好地清晰你的問題。我只需要你的導入和beforeEach函數數據。 – shiv

0

上個星期五,我終於找到了一種方法來使它工作。這並不是一個乾淨的方式,但至少在工作。

我重新導入UIRouter.forRoot與我的要素模塊的狀態,併爲UIRouter的根提供者提供APP_BASE_HREF值。

這裏是我的BeforeEach:

beforeEach(async(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ 
      HomeComponent, 
      HomeCardComponent 
     ], 
     imports: [ 
      AppMaterialModule, 
      // Always import root UIRouter module when testing a component including routing 
      UIRouterModule.forRoot({states: HOME_STATES}) 
     ], 
     providers: [ 
      // Also, include the base href value when testing a component including routing 
      {provide: APP_BASE_HREF, useValue: '/'} 
     ], 
    }).compileComponents(); 
})); 

如果你知道一個更好的辦法,我會很高興地知道! :)

相關問題