0

function:

async function signInWithPhoneNumber(phone: string) {
    setLoadingAuth(true);

    const sendSmsToPhoneNumber = httpsCallable(functions, 'sendSms');

    try {
      await sendSmsToPhoneNumber({
        phone_number: phone,
      });
      setActiveCredentialVerificationScreen(true);
    } catch (error) {
      throw error;
    } finally {
      setLoadingAuth(false);
    }
  }

this cloud function takes a phone number and returns an object:

{
    "result": {
        "success": true
    }
}
test('signInWithPhoneNumber', () => {
    const { result } = renderHook(() => useAuth(), {
      wrapper: AuthProvider,
    });

    act(() => {
      result.current.signInWithPhoneNumber('99999999999');
    });

    expect(result.current.user).toBe(null);
  });
samthecodingman
  • 23,122
  • 4
  • 30
  • 54
  • Take note how I changed the code block from using a single backtick to triple backticks to properly render your code sections. – samthecodingman Jun 07 '23 at 23:37
  • Try taking at the documentation for Jest and how you can use it to mock functions. There are various threads here on StackOverflow that go through the concept such as [this one](https://stackoverflow.com/q/65839831/3068190) and [this one](https://stackoverflow.com/q/45758366/3068190). – samthecodingman Jun 07 '23 at 23:44

0 Answers0