diff --git a/__tests__/Goals/components/TodoComponent-text.tsx b/__tests__/Goals/components/TodoComponent-text.tsx index 7887800a..b0638ce7 100644 --- a/__tests__/Goals/components/TodoComponent-text.tsx +++ b/__tests__/Goals/components/TodoComponent-text.tsx @@ -3,7 +3,18 @@ import { render, fireEvent } from '@testing-library/react-native'; import TodoComponent from '../../../src/components/ToDoComponent/TodoComponent'; import { NavigationContainer } from '@react-navigation/native'; +jest.mock('@react-navigation/native', () => { + return { + ...jest.requireActual('@react-navigation/native'), + useNavigation: jest.fn(), + }; +}); + describe('TodoComponent', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + test('renders title correctly', () => { const { getByText } = render( @@ -24,15 +35,19 @@ describe('TodoComponent', () => { expect(addButton).toBeTruthy(); }); - test.skip('calls navigationProp.navigate when "Add" button is pressed', async () => { - const navigationProp = { navigate: jest.fn() }; - const { getByTestId } = render( + test('calls navigationProp.navigate when "Add" button is pressed', async () => { + const navigate = jest.fn(); + require('@react-navigation/native').useNavigation.mockReturnValue({ + navigate, + }); + + const { getByText } = render( - + , ); - const addButton = await getByTestId('addButton'); + const addButton = getByText('Add'); fireEvent.press(addButton); - expect(navigationProp.navigate).toHaveBeenCalledWith('CreatingGoals'); + expect(navigate).toHaveBeenCalledWith('CreatingGoals'); }); }); diff --git a/jest-setup.js b/jest-setup.js index 120782ec..d3bfbbdb 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -1,6 +1,6 @@ import { jest } from '@jest/globals'; import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'; -require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests(); +require('react-native-reanimated/src/jestUtils').setUpTests(); jest.mock('react-native-device-info', () => mockRNDeviceInfo); jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');