jasmine-dom is a companion library for Testing Library that provides custom DOM element matchers for Jasmine

npm install --save-dev @testing-library/jasmine-dom

Then follow usage section from jasmine-dom's documentation to add the matchers to Jasmine.

<span data-testid="not-empty"><span data-testid="empty"></span></span>
<div data-testid="visible">Visible Example</div>
expect(screen.getByText('Visible Example')).toBeVisible()

Note: when using some of these matchers, you may need to make sure you use a query function (like queryByTestId) rather than a get function (like getByTestId). Otherwise the get* function could throw an error before your assertion.

Check out jasmine-dom's documentation for a full list of available matchers.

Last updated on by Matan Borenkraout