Skip to content

Lint for expect() calls without matchers #6

@wincent

Description

@wincent

I see quite a few instances of test code that looks like this:

expect(getByText('report'));
expect(getByRole('button'));

These don't actually assert anything (other than implicitly, that getByText()/getByRole()) didn't throw before expect() was even called. This would be equivalent:

getByText('report');
getByRole('button');

Let's add a lint against doing nothing with the return value of expect() in tests: it should always be chained with a matcher. In the examples above, that could be:

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

expect(getByText('report')).toBeVisible();
expect(getByRole('button')).toBeVisible();

or similar.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions