Skip to content

False positive for testing-library/prefer-screen-queries #366

Open
@julienw

Description

@julienw
import { render, getByText } from '@testing-library/react';
import React from 'react';

render(<div>some text</div>);

getByText(document.body, 'some text');

=> testing-library/prefer-screen-queries: Avoid destructuring queries from render result, use screen.getByTestId instead

In this case, we use the function imported from @testing-library/dom reexported from @testing-library/react that allows to search for an element in the tree of any other element (like within). This exact example is of course useless (we can use screen) but this is to show the problem with a simple testcase. I believe this is a valid use case and shouldn't be flagged by testing-library/prefer-screen-queries.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationpinnedPinned for different reasons. Issues with this label won't be flagged as stale by stalebot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions