2014-05-14 2 views
5

컨트롤러 (moduleFor('controller:name', ...) 사용)에 대한 ember-qunit 테스트 케이스가 있는데 그 중 moduleForModel -exclusive this.store()을 사용할 수 있기를 원합니다. DS.FixtureAdapter 데이터 저장소를 검색합니다. 이 특정 테스트 케이스의 경우 모델을 테스트하지 않고 컨트롤러에 모델 인스턴스 세트가 채워질 수 있는지 확인하고 해당 데이터에 대해 다양한 연산을 실행할 수 있습니다. 위의 TestController라는 이름의 컨트롤러가 및 테스트라는 이름의 모델도이 예에서상점 (DS.FixtureAdapter)이있는 컨트롤러를 테스트하기 위해 ember-qunit 사용

moduleFor("controller:test", 'My Controller', { 
    setup: -> 
    @store().createRecord 'test', value: 1 
    @store().createRecord 'test', value: 2 

    @subject({ 
     model: @store().all('test') 
    }) 
    teardown: -> App.reset() 
}, (container, context) -> 
    container.register 'store:main', DS.Store 
    container.register 'adapter:application', DS.FixtureAdapter 
    context.__setup_properties__.store = -> container.lookup('store:main') 
) 

:처럼 나는 커피 스크립트를 사용하고

내 코드 보인다 있도록. emer-qunit에 moduleForModel의 정의에서 container.registercontext.__setup_properties__.store 행을 들어 냈습니다.

Setup failed on [test case name]: No model was found for 'test' 

엠버 - qunit 잘 작동 이외의 실제 응용 프로그램을 실행 :

문제

는 엠버 - qunit 테스트 스위트를 실행했을 때 오류가 발생하는 것입니다. 이 같은 문제가있는 사람이있을 수 있습니까? 아니면 잘못된 접근 방식을 취하고 있습니까?

답변

4

테스트 모델이 컨테이너에 등록되어 있지 않아서 해결할 수없는 문제 일 수 있습니다.

당신은 당신의 테스트 모듈 콜백하는 동안 수동으로 등록 할 수 있습니다 :

container.register('model:test', TestModel) 

또는이 moduleFor의 IMPL의 요구 속성을 사용

moduleForComponent('controller:test', 'My Controller', { 

    // specify the other units that are required for this test 
    needs: ['model:test'], 
    setup: {...}, 
    teardown: {...} 
}); 
+0

감사합니다, 실종 무엇'needs' 필드이었다. 그것은 작동합니다! – jeninto