我有一个控制器我与Ember CLI测试的特性“transitionToRoute”,但控制器的承诺不会解决,因为控制器的transitionToRoute
方法返回null
:灰烬CLI控制器测试:遗漏的类型错误:无法读取空
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)
)
)
当行@transitionToRoute("dashboard")
被移除时,测试通过;否则,测试失败。
如何解决此错误,同时仍然保持我的控制器逻辑?
'transitionToRoute'不返回null,它*为* null。我猜想这不是你所怀疑的。我对coffeescript不感兴趣,无法让我担心它:) – 2014-08-31 02:47:20
如果您找到了解决方案,请将其作为答案发布,因为我面临类似的问题。 – Mawaheb 2014-12-18 14:23:04