How best to test for an empty (null) component in Vitest?

I have a React component which, when given badly configured props, returns null

screen.debug() in Vitest displays the result like this:

  <body>
    <div />
  </body>

This is expected, but what constitutes a good test for this markup?

Currently I’m testing the absence of tags that would be present if the component returned a JSX element. Does that sound right?


  • you can use the shallowMount method to mount the component and then use the exists method to check if the component exists. import { shallowMount } from '@vue/test-utils';

    – 

Leave a Comment