KnownSubset
KnownSubset

Reputation: 139

Attempting to send action on controller, causes unit test to fail for Ember.js

I am attempting to test that calling the move action will cause a modal view's controller to setup with the proper model.

asyncTest("attempting to move directories will setup the folder_tree_controller's model", 1, ->
  User.create({email: '[email protected]', 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 gist:

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

However during the test execution I error out and receive the following message:

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)

Am I missing something while attempting to test setting up the modal view?

Upvotes: 3

Views: 938

Answers (1)

kcgolden
kcgolden

Reputation: 430

Set up your controller like this and it will be able to call send in your tests:

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

This as opposed to doing the container.lookup(...)

Upvotes: 2

Related Questions