I have a controller I'm testing with Ember CLI, but the controller's promise will not resolve, as the controller's transitionToRoute
method is returning null
:
Uncaught TypeError: Cannot read property 'transitionToRoute' of null
login.coffee
success: (response) ->
# ...
attemptedTransition = @get("attemptedTransition")
if attemptedTransition
attemptedTransition.retry()
@set "attemptedTransition", null
else
@transitionToRoute "dashboard"
login-test.coffee
`import {test, moduleFor} from "ember-qunit"`
moduleFor "controller:login", "LoginController", {
}
# Replace this with your real tests.
test "it exists", ->
controller = @subject()
ok controller
###
Test whether the authentication token is passed back in JSON response, with `token`
###
test "obtains authentication token", ->
expect 2
workingLogin = {
username: "[email protected]",
password: "pass"
}
controller = @subject()
Ember.run(->
controller.setProperties({
username: "[email protected]",
password: "pass"
})
controller.login().then(->
token = controller.get("token")
ok(controller.get("token") isnt null)
equal(controller.get("token").length, 64)
)
)
When the line @transitionToRoute("dashboard")
is removed, the test passes; otherwise, the test fails.
How can I fix this error, while still maintaining my controller logic?
transitionToRoute
is not returning null, it is null.this
is not what you suspect it is, I imagine. My non-interest in coffeescript prevents me from worrying about it too much :) - Steve H.