Testing route transitions


#1

So I have a simple controller that calls transitionTo after a promise has resolved. I am looking for a way to integration test this transition.

I have mocked out the library that returns the promise so it returns a promise which then resolves. I would like to test and see that when the promise is resolved the call to transitionTo is made, and the route is changed, but I can’t figure out a way to do it.

Code below (coffeescript)…

The test:

module 'signup succeeds', {
  setup: ->
    Library.User.signup =  ->
      return new Ember.RSVP.Promise( (resolve) ->
        console.log 'resolving'
        resolve({})
      )
}

test 'the route changes', ->
  visit '/sign-up'
  andThen ->
    fillIn '.email', 'badger@me.com'
    fillIn '.password', 'giraffe'
    click 'button.login-btn'
    andThen ->
      // test the route after the promise resolves here

The controller:

App.SignUpController = Ember.Controller.extend

  email: ''
  password: ''

  actions:
    signUp: ->

      credentials =
        username: @get 'email'
        password: @get 'password'
        email: @get 'email'

      Library.User.signup credentials
        .then @callback, @errback

    callback: ->
      @transitionToRoute 'index'

    errback: (err) ->
      # TODO error reporting
      console.log err

Any help is greatly appreciated


#2

There is a property on the application controller called currentRouteName. In my tests I get the application controller via the application container:

App.__container__.lookup('controller:application').get('currentRouteName');

This will return you the path to the current route.


#3

I shared the integration tests for my blog app, here is a post on the topic: http://pixelhandler.com/posts/end-to-end-javascript-testing-integration-tests-using-emberjs-test-helpers

Basically I use the Ember Test helpers as well as a few custom helpers:

Integration tests that use the path() helper


#4

Old thread with up-to-date topic, so… You can use the following synchronous test helpers:

  • currentRouteName()
  • currentPath()
  • currentURL()

Taken from Ember docs: http://emberjs.com/guides/testing/test-helpers/#toc_synchronous-helpers