In my app I have something similar to this to signOutUser a user.
import { getAuth } from "firebase/auth";
export function signOutUser(): Promise<void> {
return getAuth(firebaseApp).signOut();
}
And I want to make sure that the signOut function of firebase is called.
But I can't figure how to mock and spy on the sign out function that is on the auth object.
One attempt I've done...
I'm mocking these functions from firebase/auth like so...
const mockSignOut = jest.fn();
jest.mock("firebase/auth", () => {
return {
__esModule: true,
getAuth: jest.fn().mockImplementation(() => {
return {
signOut: mockSignOut,
};
}),
};
});
I get ReferenceError: Cannot access 'mockSignOut' before initialization .
If I change it to var I get TypeError: signOut is not a function
The documentation I think this is kind of close to what I want? But it doesn't explain how you would mock a mocked value that I understand at least https://jestjs.io/docs/es6-class-mocks#manual-mock
How can I spy on this signOut function from the object that getAuth() returns and is also mocked?