In an initializer, I'm injecting an object into my helper, and it works properly in the App.
But when testing the helper with QUnit, I get the following error:
TypeError: undefined is not a function.
The helper doesn't have access to the injected object, although when calling App.__container__.lookup('myObject:main')
within the setup function of the module, it does return the object.
How can I make this work? The test class is based on fiddle1, fiddle2.
The following example in CoffeeScript shows my problem:
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 "#ember-testing"
return
return
Ember.Handlebars.helper "upcase", (value) ->
person = @get('person'); # <-- test fails here
value += person.name;
value.toUpperCase()
Ember.testing = true
test('non-redirect route /third', ->
equal(initializedCount, 2, 'initializer ran');
App.reset();
equal(initializedCount, 3, 'initializer ran');
App.reset();
equal(initializedCount, 4, 'initializer ran');
);
test "a handlebars helper", ->
view = createView("{{upcase 'something'}}")
append view
equal view.$().text(), "SOMETHING MARY"
return