I'm new to testing and very confused on what I need to do to thoroughly test my MealsSummary.tsx
component. I want to start with testing if my component is retrieving items
from the redux store
correctly. I found a couple answers from SO to setup my mock function, though I'm unsure if the setup is correct. If it is, what should I do next in terms of testing my 'useSelector' mock function. Ty in advance
MealsSummary.test.tsx
describe('mock ', () => { jest.mock("react-redux", () =>({ ...jest.requireActual("react-redux"), useSelector: jest.fn() })) describe("testing useselector", () => { const mockedState = { user: { image: 'null', name: 'testing', id: 'name+date', calories: 2000, proteins: 150, carbohydrates: 200, fats: 90, }, }; test('get items', () =>{ //not sure what to write }) });})
MealsSummary.tsx
import { useSelector } from "react-redux"import { RootState } from "../../redux/store";import { ScrollView, StyleSheet, Text} from "react-native"import { MealCard } from './MealCard'export const MealsSummary = (): JSX.Element => { const { items } = useSelector((store: RootState) => store.nutrition) let title: string = 'Food' return (<><Text style={styles.title}>{title}</Text><ScrollView > {items.map(item => (<MealCard item={item} key={item.id}/> ))}</ScrollView></>)}