小编eff*_*fel的帖子

Ember.js:单元测试一个有依赖注入的帮助器?

在初始化程序中,我将一个对象注入我的帮助程序,它在应用程序中正常工作.

但是当使用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)

ember.js ember-qunit

14
推荐指数
1
解决办法
1165
查看次数

标签 统计

ember-qunit ×1

ember.js ×1