Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

How to write the test for useSelector with Jest

$
0
0

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></>)}

Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>