I have a login form and now i would like to make an integration test to see if user is redirected to the other page after successful login.
Behind the curtains there is authorization service that fires a page reload via $window.location.href = 'home';
First i had this:
it('should redirect to /home if credentials are correct', function(){
browser().navigateTo('/login');
input('credentials.username').enter('testuser');
input('credentials.password').enter('testpass');
element('button.login').click();
expect(browser().location().path()).toBe("/home");
});
but AngularJS test failed both - run as Karma and as runner in browser. Then i thought that maybe expect
is too soon and i added sleep(1)
before it. And then it was fine and in test runner I could see the page refresh before assertion.
I assume it might work better if i had location().path('/home') but i prefer full reload at this step.
Is there any design/test pattern that should be used in such cases so i don't have to put sleep() before expected location change?