2017-10-04 4 views
1

나는 지정된 모듈이 정의 된대로 디스크에 존재한다는 것을 알기 위해 응용 프로그램에서 구성한 유닛 테스트 경로에 대한 좋은 패턴을 찾고있었습니다.Aurelia unit 모듈의 경로 테스트

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(); 
     //}); 
    }); 
}); 

나의 현재를 :

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"; 
} 

내가 그때가 존재하는지 확인 라우터의 인스턴스에 전달하는 접근을했다 테스트하려면 : 여기

는 예를 들어 경로 구성입니다 문제는 현재 테스트에 표시된 것처럼 컨테이너가 null 라우터를 반환한다는 것입니다. 내가하려는 일에 가장 가까운 패턴은 this question입니다.

예제 테스트에서 누락 된 점은 무엇이며 경로 구성을 테스트하는 더 좋은 방법이 있습니까?

+0

코드를 그대로 복사하면 작동합니다. 라우터가 null이 아니고 테스트가 통과됩니다. – thinkOfaNumber

+0

@thinkOfaNumber 테스트를 실행 해 주셔서 감사합니다. 내가 카르마를 어떻게 세우 느냐에 대한 의존성이 드러났습니다. 때때로 다른 날에 신선한 모양이 문제를 해결합니다. –

+0

여러분을 환영합니다! – thinkOfaNumber

답변

0

@thinkOfaNumber가 맞았습니다. 내 테스트가 좋았지 만 반사 메타 데이터가 누락되었습니다. this stackoverflow post에 나와있는 수정 사항을 적용했을 때 테스트가 통과되었습니다.