score:1

Here is how I use this great library :

// in test file
import '@testing-library/jest-dom/extend-expect';

[...]

// then matchers are available in tests
expect(rtl.getByText('text').toHaveClass('some-class');

My import is slightly different than yours, I could not say precisely what goes wrong with yours but this is how I do.

Good luck !

score:2

Well, jest-dom documentation has been updated.

import {toHaveStyle} from '@testing-library/jest-dom';

would not work anymore. Instead,

import {toHaveStyle} from '@testing-library/jest-dom/matchers'

For reference, see jest-dom


Related Query

More Query from same tag