2014-02-08 2 views
1

저는 Ember에게 새로운 제품이며 Konacha를 사용하여 내 앱을 테스트하고 있습니다. 내 테스트에서 데이터 저장소를 사용하는 데 문제가 있습니다. 다음 코드는 Item 모델의 itemText 속성은 DOM에 표시된 텍스트와 같은 경우는 확인을 시도 : 분명히테스트에서 Ember 속성을 가져 오면 정의되지 않음

it "should display the item text", -> 
    item = undefined 
    Ember.run -> 
    item = store.find('item', 1) # store is defined in the spec helper 
    content = item.get('itemText') 
    console.log(item)    # Logs the correct item 
    console.log(content)   # Logs undefined 
    $('.list-item:eq(0)').text().should.equal content # Fails since content is undefined 

content = item.get('itemText') 내가 그것을 기대하고있어 일을하지 않습니다. 그러나 콘솔에서 같은 코드를 한 줄씩 실행하면 내가 원하는 속성을 다시 얻을 수 있으므로 어디서 잘못 될지 잘 모르겠습니다. 나는 이것을 완전히 잘못된 방향으로 테스트하고 있을지도 모르는 느낌이 들었으므로 어떤 의견이라도 환영받습니다.

답변

3

모델을 가져 오기 전에 콘솔 로그가 실행되었다고 생각합니다. 당신이 필요로하는 것은 약속입니다.

it "should display the item text", -> 
    item = undefined 
    Ember.run -> 
    item = store.find('item', 1).then (item) -> 
     content = item.get('itemText') 
     $('.list-item:eq(0)').text().should.equal content 
+0

굉장, 고마워! 나는'.find()'호출을'store.find ('item', 1) .then (item) ->'호출자를 핸들러로 넘겨 주어야하지만, 돈. – Sean

+0

위대한, 나는 대답을 업데이 트했습니다 :). – MartinElvar

관련 문제