我是Ember的新手,正在使用Konacha来测试我的应用程序。我在测试中无法使用数据存储。以下代码尝试检查模型的itemText
属性Item
是否等于DOM中显示的文本:
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')
它没有按照我的期望去做。但是,在控制台中逐行运行相同的代码会带回我想要的属性,因此我不确定哪里出了问题。我觉得我可能会以完全错误的方式对此进行测试,因此,感谢您提供任何反馈意见。
我认为在获取模型之前已运行控制台日志。您需要的是一个承诺,看看吧。
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句