Testing a CallBack function in a function which get triggered forButton Onclick using jest


I have a React child component which has button

export function Banner({argumentSetter}){
function handleOnClick(){
  argumentSetter(argument.READ);
}
return(
<div>
  <Button onClick={handleOnClick}>
    <Icon name="delete" type="filled">
      Discard
    </Icon>
  </Button>
</div>
)
}

And I have my argumentSetter in my parent component defined as following,

const [argument,setArgument] = useState<Argument>(argument.EDIT);
argumentSetter = useCallBack((val)=>{
setArgument(val);
},[argument]);

return(
  <div>
    <Banner argumentSetter={argumentSetter}/>
  </div>
)

How to get 100% test coverage using jest.

Source: React – Stack Overflow

November 22, 2021
Category : News
Tags: jestjs | mocking | reactjs | spy

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.