-1

`

it('Should render ComB when parameter value=A', () => {
    const {container} = render(<ComB/>);
     expect(container).toBeInTheDocument()
  });

`I want write a jest test case for following code as it show branch coverage 50% and point out for this code.

export default function TestCom(){
  const parameter=useParams();
  return(
    <>
      {
        parameter.value==="A" ? 
        (<ComB/>) : 
        (parameter.value==="B" && <ComC/>)
      }
    </>
  )
}

I am fetching query parameter value and based upon the parameter value conditionally rendering the "components". So can anyone please help how can I write jest test cases for this ternary operator.

supriya
  • 1
  • 2

1 Answers1

0

50% branch coverage just means you're not reaching the other half of your code within the ternary. You need to have 2 tests, one where parameter.value will equal "A" and another test where it doesn't. It would help if you also showed what your test looks like.

Matt Coady
  • 3,418
  • 5
  • 38
  • 63