Home > Mobile >  What value to give void properties
What value to give void properties

Time:05-31

I have this interface:

interface Props {
    close: () => void;
    disableButton: () => void;
    showPrompt: boolean;
    pol: string;
}

I'm trying to use it in a test. My problem is that I don't know what I should do with close and disableButton. They are just passed to that class so the state can be updated. What value do I give the variables for use in my shallow?

describe('<Reissue />', () => {
    it('calls reissue service', () => {
        const close = ???;
        const disableButton = ???;
        const showPrompt = true;
        const pol = '123456';

        const wrapper = shallow(<Reissue close={} disableButton={} showPrompt={showPrompt} pol={pol}/>);
    });    
});

CodePudding user response:

close and disableButton are functions so you should pass functions to them, even if empty empty ones -

const wrapper = shallow(<Reissue close={()=>()} disableButton={()=>()} showPrompt={showPrompt} pol={pol}/>);

CodePudding user response:

The void keyword in this context is used to indicate that the function returns no value, hence you can just use an empty closure () => {}.

If you are using jest, you can also use jest.fn(), which will behave the same but has the benefit of capturing information that will help you during your tests (e.g. how many times the function have been called)

https://jestjs.io/docs/mock-functions

  • Related