katowulf / mockfirebase

Firebase mock library for writing unit tests (experimental)
157 stars 40 forks source link

changeAuthState does not trigger resolution for authWithOAuth #86

Closed ajcrites closed 9 years ago

ajcrites commented 9 years ago

I'm using angularfire and have $firebaseAuth(ref).$authWithOAuthPopup called.

.then(authData => sessionAuth = authData)
.then(auth.createUser)

This works in my app, but I want to be able to test the user's login. In my test, I have:

authService.doPopup();
authService.ref.changeAuthState({uid: "test"});
authService.ref.flush();
expect(auth.createUser).to.have.been.called;

However, auth.createUser is not called. .then is not being called. After some digging, I've found that AngularFire does seem to be resolving the deferred internally but this doesn't propagate to .then being called.

Am I doing something incorrectly / is there a better way to do this test, or is this just an issue?

bendrucker commented 9 years ago

You need to call $timeout.flush() after injecting $timeout. Otherwise Angular won't try to resolve the promise. This is a general Angular testing requirement and not specific to MockFirebase.