2017-10-04 2 views
1

私は、指定されたモジュールが定義されたディスク上に存在することを知るために、自分のアプリケーションで設定した単体テストルートに対する良いパターンを探していました。ここでモジュールへのAureliaユニットのテスト経路パス

は、例えば、ルート設定である:

import { Aurelia, PLATFORM } from 'aurelia-framework'; 
import { Router, RouterConfiguration } from 'aurelia-router'; 

export class App { 
    params = new bindParameters(); 
    router: Router; 


    configureRouter(config: RouterConfiguration, router: Router) { 
     config.title = 'Aurelia'; 
     config.map([{ 
      route: ['', 'home'], 
      name: 'home', 
      settings: { icon: 'home' }, 
      moduleId: PLATFORM.moduleName('../home/home'), 
      nav: true, 
      title: 'Home' 
     }, { 
      route: 'sample', 
      name: 'sample', 
      settings: { icon: 'education' }, 
      moduleId: PLATFORM.moduleName('../sample/index'), 
      nav: true, 
      title: 'Sample Information' 
     }]); 

     this.router = router; 
    } 
} 

class bindParameters { 
    user = "user_name"; 
} 

それをテストするために私はそれが存在するかどうかをチェックし、ルータのインスタンスを渡すのアプローチを取った:

import { App } from './app'; 
import jasmine from 'jasmine'; 
import { Container } from "aurelia-framework"; 
import { RouterConfiguration, Router } from "aurelia-router"; 

describe('application routes', function() { 
    let app: App; 
    let router: Router; 
    let routerConfiguration: RouterConfiguration; 
    let configureRouter: Promise<void>; 

    beforeEach(() => { 
     var container = new Container().makeGlobal(); 
     routerConfiguration = container.get(RouterConfiguration); 
     router = container.get(Router); 
     app = new App(); 
     app.configureRouter(routerConfiguration, router); 
     configureRouter = router.configure(routerConfiguration); 
     routerConfiguration.exportToRouter(router); 
    }); 

    it('should exist for sample', function() { 
     expect(router).not.toBeNull(); 
     //configureRouter.then(function() { 
     //var route = router.routes.find((route) => route.name == 'sample'); 
     // add some assert that the sample module can be found 
     // done(); 
     //}); 
    }); 
}); 

私の現在問題は、現在のテストで示されているように、コンテナがnullルータを返すことです。私がやろうとしていることに最も近いパターンはthis questionです。

私のテストでは何が分かりませんが、ルート設定をテストするための良い方法がありますか?

+0

コードをそのままコピーすると動作します。ルータはヌルではなく、テストに合格します。 – thinkOfaNumber

+0

@thinkOfaNumberテストを実行していただきありがとうございます。私はカルマをどのようにセットアップするかに依存していたことが分かります。時には別の日に新鮮な外観が問題を解決します。 –

+0

あなたは大歓迎です! – thinkOfaNumber

答えて

0

@thinkOfaNumberが正しいようです。私のテストは良かったが、リフレクションメタデータが欠けていた。 this stackoverflow postに記載されている修正を適用すると、私のテストは合格となりました。

関連する問題