Skip to content

queryByText() error #233

Closed
Closed
@serggin

Description

@serggin

Versions

"react": "16",
"react-native": "0.61.4",
"react-native-testing-library": "^1.11.1",
"react-test-renderer": "16.9.0"

Description

The "doc" says:

queryBy
queryBy* queries returns the first matching node for a query, and return null if no elements match. This is useful for asserting an element is not present.

But in my test there must be 2 matching nodes. I am expecting the first one, but receive an error

Error: Expected 1 but found 2 instances

Reproducible Demo

test('test3 Text content', () => {
const mock = {
content: 'Some test content',
content2: 'Another test content',
typo: 'testo',
};
const component = () => (

{mock.content2}
{mock.content}

);
const {queryAllByText, queryByText} = render(component());

const q1 = queryByText('content');
expect(q1).toBeNull();
const q2 = queryByText(/content/);
expect(q2).not.toBeNull();
const q3 = queryAllByText(/content/);
console.log(q3.length);
expect(q3.length).toBe(2);

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions