2015-01-27 3 views
5

나는 이니셜 라이저가 stdlib입니다. 이 초기화 프로그램에서 내장 Ember 클래스 중 일부를 다시 열고 사용자 정의 메서드를 추가합니다. 예를 들어, Ember.EnumerableArrayreverseEach을 추가했습니다.단위 테스트에서 이니셜 라이저 사용?

그들은 애플 리케이션에서 잘 작동하지만 테스트에서 "reverseEach : undefined is not function"을 수신합니다.

테스트에서 이니셜 라이저를 사용해야 함을 어떻게 나타 냅니까?

나는 needs: [..., 'initializer:stdlib']을 시도했다. 그것은 비틀 거림이 아니지만 "정의되지 않은"오류가 나타납니다.

`import { test, moduleForModel } from 'ember-qunit'` 

moduleForModel 'foo', 'foo', 
    needs: [ 
    'model:bar' 
    'initializer:stdlib' 
    ] 

test 'deleteLastNItems', -> 
    model = @subject() 
    model.set '', ['foo', 'bar', 'baz', 'quux'] 
    model.deleteLastNItems 2 # This should not die with "reverseEach: undefined is not a function" 
    deepEquals model.get('someProperty'), ['foo', 'bar'] 

답변

-1

당신은이 테스트를 포함하여, 당신을 위해 샘플 코드를 생성합니다 ember g initializer stdlib를 사용할 수 있습니다

여기 예를 들어 테스트입니다.

import Ember from 'ember'; 
import { initialize } from '../../../initializers/stdlib'; 
import { module, test } from 'qunit'; 

var registry, application; 

module('Unit | Initializer | stdlib', { 
    beforeEach: function() { 
    Ember.run(function() { 
     application = Ember.Application.create(); 
     registry = application.registry; 
     application.deferReadiness(); 
    }); 
    } 
}); 

// Replace this with your real tests. 
test('it works', function(assert) { 
    initialize(registry, application); 

    // you would normally confirm the results of the initializer here 
    assert.ok(true); 
}); 

는 참조 : Ember blueprints

+1

문제가 초기화 자체 테스트하지만 방법 메소드 이니셜에서 원숭이 패치를 사용하는 다른 장치 (.. 예를 들어 모델)를 테스트하는 방법이 아니다. –

+0

ko 원숭이 패치 방법을 Ember.mixin으로 추출한 다음 이니셜 라이저 대신 Mixin을 가져올 수 있습니다. – zhenhua

+0

저는 모델이 아닌 Ember 자체를 원숭이 패치합니다. 예를 들어'Ember.MutableArray'에 새로운 메소드를 추가합니다 : 새로운 배열을 반환하기보다는 주어진 배열을 수정하는'.destructiveMap()'메소드. –