'E2E vs Unit Testing - Querying priority

When I was reading about querying in e2e and unit testing I found one inconsistency. According to the official Cypress documentation, it's very recommended to query tested elements by using custom data- attribute. However, according to React Testing Library documentation, for unit testing we should try to avoid data- attribute for querying, which is basically the opposite.

Could you please explain why the same logic is not applied for both kind of tests? I can understand the reason behind unit testing and queries that reflect real user interactions but why the same logic is not advised in e2e?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source