尝试在控制器上发送操作,导致Ember.js的单元测试失败

时间:2014-01-27 19:09:22

标签: unit-testing ember.js

我试图测试调用move动作会导致模态视图的控制器使用正确的模型进行设置。

asyncTest("attempting to move directories will setup the folder_tree_controller's model", 1, ->
  User.create({email: 'user@email.com', session: 'session_token', card: Cards.FIXTURES[0].id})
  cardController = App.__container__.lookup('controller:card')
  Em.run -> cardController.set('model', null)

  Em.run -> controller.send('move')
  wait()

  ok(cardController.get('model'))
  start()
)

控制器要点:

Controller = Ember.Controller.extend({
  actions: {
    move: ->
      self = @
      @get('store').find('card', User.current().directory).then (card) ->
        self.send('showMoveDialog', card)
      false
   }
})

但是在测试执行期间,我输出错误并收到以下消息:

Error: Can't trigger action 'showMoveDialog' because your app hasn't finished transitioning into its first route. To trigger an action on destination routes during a transition, you can call `.send()` on the `Transition` object passed to the `model/beforeModel/afterModel` hooks.
Source:     
    at Test.QUnitAdapter.Test.Adapter.extend.exception (http://localhost:8000/vendor/ember/index.js:40219:5)
    at superWrapper [as exception] (http://localhost:8000/vendor/ember/index.js:1230:16)
    at Ember.RSVP.onerrorDefault (http://localhost:8000/vendor/ember/index.js:16520:28)
    at Object.__exports__.default.trigger (http://localhost:8000/vendor/ember/index.js:8399:13)
    at Promise._onerror (http://localhost:8000/vendor/ember/index.js:9123:16)
    at Promise.publishRejection (http://localhost:8000/vendor/ember/index.js:9530:17)
    at Object.DeferredActionQueues.flush (http://localhost:8000/vendor/ember/index.js:5654:24)
    at Object.Backburner.end (http://localhost:8000/vendor/ember/index.js:5745:27)

我在尝试测试设置模态视图时是否遗漏了某些内容?

1 个答案:

答案 0 :(得分:2)

像这样设置你的控制器,它将能够在你的测试中调用send:

cardController = App.CardController.create({
    container: App.__container__
});

这与执行容器 .lookup(...)

相反