我正在嘗試編寫我的AngularJS應用程序的端到端測試,其中檢查URL的某個參數何時發生。但是,$routeParams
是一個空對象。 This guy也有同樣的問題。我試圖確定當?code=whatever
位於URL中時,UI中會出現一些文本。我的應用程序的工作原理,以及這條路線做什麼的預期:
$routeProvider.when '/',
resolve:
redirect: ($location, $routeParams, $http, $cookieStore) ->
console.log $routeParams
code = $routeParams.code
console.log 'code: ' + code
if code
// do something
else
// do something else
當我通過噶測試跑步參觀test-index.html?code=123
,在瀏覽器控制檯我看到:
Object {}
code: undefined
我希望有模擬出$routeParams
在單元測試中,但我假設端到端測試會像真正的應用程序一樣運行。爲什麼$routeParams
在我的測試中完全清空,肯定存在URL參數?
編輯:這裏是我的測試:
it 'fills in the input field when code is in URL', ->
browser().navigateTo '/base/test-index.html?code=123#/'
element('a.some-link').click()
expect(input('my_param.value').val()).toBe 'something that gets set when code in URL'