3

I have been trying to write a test to check for a redirect page from a backend api. I am expecting a 401 redirect to a login view however the tests show the page I should redirect to if I am already logged in.

I can only assume that the logged in view has already been placed in the $location.path before the call to the api and then the response is coming back after the test has finished. Is there any way to test this or am I on the right track.

My test code is:

window.jQueryFunction('.loginButton', 'click');
expect(browser().location().url()).toBe('/Login');

in my app.js file I test for the 401 using angular event broadcasts

$rootScope.$on('event: auth-loginRequired', function() {
    window.location = '/login'
});

can someone tell me if I am in the right ball park or am I way off mark here.

4

1 回答 1

0

401 是一个 http 错误,而不是重定向。大多数服务器发送 302(永久移动),但有时开发人员会更改内容以发送 301(临时移动)。此外,您还应该测试 location.path() 而不是 window.location 的值。

于 2013-10-04T15:30:56.473 回答