我有一個控制器我與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