vendredi 6 novembre 2020

How to test conditionally rendered component based on hook in react native

I"m trying to find out how to unit test a whether a block or red or green depending on the current state (using hooks). The 'button' is rendered if the state(isHistory) contains an item in the form :

item: {
                first_name: 'kevin',
                last_name: 'bacon',
                charge_amount: '-50',
                reversed: false,
        
            },

If the state determines that the item exists, the button should render, otherwise it will not. My problem is being able to mock the isHistory state to contain this item so that my unit test would work.

 const {getByTestId} = render(
             <Provider theme={theme}>
             <Here  {...mockProps}/>
         </Provider>,
             );

expect(getByTestId('button')).toBeTruthy();

Aucun commentaire:

Enregistrer un commentaire