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