$authWithPassword requires browser.sleep with e2e tests
My application is using $authWithPassword, and inside the ".then" callback, I am redirecting to a different state (using ui-router).
authObj.$authWithPassword({
email: that.email,
password: that.password
}).then(function(data) {
$state.go("nextState");
})
Here is part of the test:
//login clicks a button that authenticates using the code above
login().then(() => {
browser.sleep(1000);
expect(browser.getCurrentUrl()).toContain("next");
});
There aren't many examples regarding this online. It seems like mainly an issue with how angularfire works, however. The problem is, if I do not put in the sleep, protractor won't wait for angularfire's promise returned by the auth.
Please include a minimal repro. Can't reproduce with what you have here.
Without the
browser.sleep
The test would fail.
No repro included.
@katowulf
this.loginWithPass = function() {
authObj.$authWithPassword({
email: that.email,
password: that.password
}).then(function(data) {
$state.go("nextState");
})
}
E2E
//login clicks a button that authenticates using the code above
function login() {
//click executes login.Pass
loginButton.click();
}
login().then(() => {
expect(browser.getCurrentUrl()).toContain("next");
});
expect doesn't wait for the promise to finish
This still isn't a repro. See creating an mcve. Where does loginWithPass() get called from? What versions are we working with? I can't run this.
At first glance, there's no promise involved in this process, other than the one returned by the button click. If you want it to wait for the promise, you have to involve that in some way. The promise is returned by authObj.$authWithPassword(), and since you aren't returning that (just going to a new screen) there's really no way to make your e2e test wait on it.
I suppose you could improvise by monitoring $state's events and seeing when $go() is called?
<div ng-controller="TestController as tc">
<button ng-click="ac.login()"></button>
</div>
JS
angular.module("test", [])
.controller("TestController", function() {
this.login() {
return authObj.$authWithPassword({
email: that.email,
password: that.password
}).then(function(data) {
$state.go("nextState");
return data;
}
})
E2E
//login clicks a button that authenticates using the code above
function login() {
//click executes login.Pass
loginButton.click();
}
login().then(() => {
expect(browser.getCurrentUrl()).toContain("next");
});
Protractor version 3.1.1 angularfire 1.1.2
@maneesht that's not a repro. login() doesn't return anything and this won't compile. There are missing brackets. See creating an mcve. Attach a minimal repro that runs or a failing test unit as a PR for demonstration.
[redacted; unrelated to this bug]
@liveakshay your error is with failNetx() and MockFirebase and looks unrelated to this one. Additionally, this issue is closed. I've moved your question to a new issue.