在初始化程序中,我将一个对象注入我的帮助程序,它在应用程序中正常工作.
但是当使用QUnit测试帮助程序时,我收到以下错误:
TypeError:undefined不是函数.
帮助程序无法访问注入的对象,尽管在App.__container__.lookup('myObject:main')模块的setup函数内调用时,它确实返回了对象.
我怎样才能做到这一点?测试类基于fiddle1,fiddle2.
CoffeeScript中的以下示例显示了我的问题:
App = undefined
entered = false
initializedCount = 0
module 'testing',
setup: ->
App = startApp()
teardown: ->
Ember.run(App, 'destroy')
Ember.Application.initializer({
name: "person",
initialize: (container, application) ->
initializedCount++;
person = {
name: "Mary"
}
container.register('person:main', person, {instantiate: false});
container.injection('helper', 'person', 'person:main');
});
createView = (template, context) ->
context = {} unless context
View = Ember.View.extend(
controller: context
template: Ember.Handlebars.compile(template)
)
View.create()
append = (view) ->
Ember.run ->
view.appendTo …Run Code Online (Sandbox Code Playgroud)