I'm trying to write an end-to-end test of my AngularJS app where I check that when a certain parameter is in the URL, something happens. However, $routeParams
is an empty object. This guy had the same problem. I'm trying to determine that some text appears in the UI when ?code=whatever
is in the URL. My app works, and this route does what's intended:
$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
When I visit test-index.html?code=123
via the Karma test runner, in the browser console I see:
Object {}
code: undefined
I would expect to have to mock out $routeParams
in a unit test, but I assumed an end-to-end test would function like the real app. Why is $routeParams
completely empty in my test when there is definitely a URL parameter?
Edit: here is my test:
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'