我正在尝试编写我的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'