mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-01-01 10:28:40 -05:00
* Don't require TS extensions in imports * Resolve all import extension errors * Remove file extension from import paths used in mocks * Remove .d of type definition file paths * Remove .d of type definition file and import as type --------- Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
import { render, screen } from "@testing-library/react-native";
|
|
import HideView from "components/SharedComponents/HideView";
|
|
import React, { useEffect } from "react";
|
|
import { Text } from "react-native";
|
|
|
|
const testFunc = jest.fn();
|
|
|
|
const TEST_TEXT = "Centipedes";
|
|
|
|
const TestComponent = () => {
|
|
useEffect( () => {
|
|
testFunc();
|
|
}, [] );
|
|
|
|
return <Text>{TEST_TEXT}</Text>;
|
|
};
|
|
|
|
describe( "HideView", () => {
|
|
afterEach( () => {
|
|
jest.clearAllMocks();
|
|
} );
|
|
|
|
test( "should show component correctly", () => {
|
|
render(
|
|
<HideView show>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).toHaveBeenCalledTimes( 1 );
|
|
|
|
expect( screen.queryByText( TEST_TEXT ) ).toBeVisible();
|
|
} );
|
|
|
|
test( "should hide component correctly", () => {
|
|
render(
|
|
<HideView show={false}>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).toHaveBeenCalledTimes( 1 );
|
|
expect(
|
|
screen.queryByText( TEST_TEXT, { includeHiddenElements: true } )
|
|
).not.toBeVisible();
|
|
} );
|
|
|
|
test( "should not render hidden component", () => {
|
|
render(
|
|
<HideView show={false} noInitialRender>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).not.toHaveBeenCalled();
|
|
expect( screen.queryByText( TEST_TEXT ) ).not.toBeTruthy();
|
|
} );
|
|
} );
|