import { render, screen } from "@testing-library/react-native"; import HideView from "components/SharedComponents/HideView.tsx"; import React, { useEffect } from "react"; import { Text } from "react-native"; const testFunc = jest.fn(); const TEST_TEXT = "Centipedes"; const TestComponent = () => { useEffect( () => { testFunc(); }, [] ); return {TEST_TEXT}; }; describe( "HideView", () => { afterEach( () => { jest.clearAllMocks(); } ); test( "should show component correctly", () => { render( ); expect( testFunc ).toHaveBeenCalledTimes( 1 ); expect( screen.queryByText( TEST_TEXT ) ).toBeVisible(); } ); test( "should hide component correctly", () => { render( ); expect( testFunc ).toHaveBeenCalledTimes( 1 ); expect( screen.queryByText( TEST_TEXT, { includeHiddenElements: true } ) ).not.toBeVisible(); } ); test( "should not render hidden component", () => { render( ); expect( testFunc ).not.toHaveBeenCalled(); expect( screen.queryByText( TEST_TEXT ) ).not.toBeTruthy(); } ); } );