soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
349 stars 97 forks source link

changeAuthState not triggering onAuthStateChanged observer #137

Closed p12y closed 5 years ago

p12y commented 5 years ago

In my component I have an observer listening for auth state change:

firebase.auth().onAuthStateChanged(async (user) => {
 // Set user state
});

In my test, I am changing the auth state like so:

const wrapper = mount(<Root />);
mockFirebase.auth().changeAuthState({
  uid: 'testUid',
  provider: 'email',
  token: 'authToken',
  expires: Math.floor(new Date() / 1000) + 24 * 60 * 60,
  auth: {
    isAdmin: true
  }
});
mockFirebase.auth().flush();
wrapper.update();

The problem is that changing the auth state in my test is not triggering the observer, meaning the state doesn't get updated in the component during the test.

Is this a bug, or am I misunderstanding the implementation of this? Thanks.

p12y commented 5 years ago

Closing this as it was a mistake in my implementation.

calendee commented 4 years ago

@p12y Do you have an updated sample of how you're doing this? I have the same example code you described above.

How are you making this work now?