import React from "react"; import { fireEvent, render, screen, waitFor, } from "@testing-library/react-native"; import { AccessibilityInfo } from "react-native"; import { Toast, showToast } from "."; import { Button } from "../Button"; import { MockSafeAreaProvider } from "../utils/test"; interface ToastSetupProps { bottomOffset?: number; message?: string; } async function expectToastWithMessage(message: string): Promise { expect(await screen.findByText(message)).toBeDefined(); await waitFor(() => { // We also need to assert the accessibility info because otherwise // the test will 'overflow' and cause other tests to fail. expect(AccessibilityInfo.announceForAccessibility).toHaveBeenCalledWith( message, ); jest.mocked(AccessibilityInfo.announceForAccessibility).mockClear(); }); } function setup({ bottomOffset, message = "Notify message" }: ToastSetupProps) { return render(