I have a controller that I am testing with the Ember CLI, but the promise of the controller will not be resolved since it returns the controller transitionToRoute null:
Uncaught TypeError: Cannot read the 'transitionToRoute' property from 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", {
}
test "it exists", ->
controller = @subject()
ok controller
test "obtains authentication token", ->
expect 2
workingLogin = {
username: "user@pass.com",
password: "pass"
}
controller = @subject()
Ember.run(->
controller.setProperties({
username: "user@pass.com",
password: "pass"
})
controller.login().then(->
token = controller.get("token")
ok(controller.get("token") isnt null)
equal(controller.get("token").length, 64)
)
)
When the row @transitionToRoute("dashboard")is deleted, the test passes; otherwise, the test fails.
How can I fix this error while maintaining my controller logic?
source
share