Skip to content

Conversation

@HassanBahati
Copy link
Member

@HassanBahati HassanBahati commented Sep 25, 2024

this pr adds tests to useSignInAnonymouslyMutation hook

@docs-page
Copy link

docs-page bot commented Sep 25, 2024

To view this pull requests documentation preview, visit the following URL:

react-query-firebase.invertase.dev/~103

Documentation is deployed and generated using docs.page.

} from "firebase/auth";
import { useSignInAnonymouslyMutation } from "./useSignInAnonymouslyMutation";

vi.mock("firebase/auth", () => ({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ehesp i did have 2 options here when mocking the firebase auth module

  1. Option One (seemed simple and its what i went with)
// this ignores all other imports from the module 
// and only mocks the specific function 'signInAnonymously'
vi.mock("firebase/auth", () => ({
  signInAnonymously: vi.fn(),
}));
  1. Option Two
//
vi.mock("firebase/auth", async (importOriginal) => {
  // Import the original 'firebase/auth' module
  const module = await importOriginal<typeof import("firebase/auth")>();

  // Return a mocked version of the module
  return {
    ...module, // Spread in all the original functions from the module
    signInAnonymously: vi.fn(), // Mock the specific function 'signInAnonymously'
  };
});

do you think it would be better to with option 2 that returns a mocked version of the module with all original functions ?

@HassanBahati HassanBahati requested a review from Ehesp September 25, 2024 17:54
@Ehesp Ehesp merged commit 2e73cfa into invertase:next Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants