Search code examples
bunit

In bUnit how do I verify an element does not exist


I have the following code:

var li = renderedComponent.Find("li.validation-message");
Assert.Null(li);

The Find() call is throwing an exception instead of returning null. And HasComponent<>() needs a type. It's not clear what type to put in that.


Solution

  • There is a FindAll function. That throws no exception if there are no elements, so there is a possibility to check for 0 items

    var validationMessages = renderedComponent.FindAll("li.validation-message");
    Assert.That(validationMessages, Is.Empty);