You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: Lack of tools to help avoid common mistakes and bad practices in test files.
In project worked on by multiple developers, it can be difficult to follow best practices and avoid common mistakes when in comes to testing. Developers may miss important aspects like missing assertions, unused queries, or problematic testing patterns. Without proper tooling, it's challenging to maintain consistency and catch these errors early in the development process.
Solution:
Adding eslint-plugin-testing-library to ensure that developers follow recommended practices when writing tests with React Native Testing Library. This includes enforcing conventions, preventing common mistakes, and promoting readable and maintainable test code.
This library offers specific presets tailored for different testing libraries. For React Native Testing Library, we can utilize the React preset, ensuring that the rules are optimized for the nuances of testing in a React Native environment. This preset streamlines the configuration process, making it easy for teams to adopt eslint-plugin-testing-library without extensive setup overhead.
The plugin provides a set of rules that can be configured in ESLint configuration file. These rules cover various aspects of testing with RNTL, such as preferring specific query methods, enforcing async/await usage, discouraging direct DOM access, and more.
Problem: Lack of tools to help avoid common mistakes and bad practices in test files.
In project worked on by multiple developers, it can be difficult to follow best practices and avoid common mistakes when in comes to testing. Developers may miss important aspects like missing assertions, unused queries, or problematic testing patterns. Without proper tooling, it's challenging to maintain consistency and catch these errors early in the development process.
Solution:
Adding eslint-plugin-testing-library to ensure that developers follow recommended practices when writing tests with React Native Testing Library. This includes enforcing conventions, preventing common mistakes, and promoting readable and maintainable test code.
This library offers specific presets tailored for different testing libraries. For React Native Testing Library, we can utilize the React preset, ensuring that the rules are optimized for the nuances of testing in a React Native environment. This preset streamlines the configuration process, making it easy for teams to adopt eslint-plugin-testing-library without extensive setup overhead.
The plugin provides a set of rules that can be configured in ESLint configuration file. These rules cover various aspects of testing with RNTL, such as preferring specific query methods, enforcing async/await usage, discouraging direct DOM access, and more.
It is worth noting that this approach is recommended by RNTL maintainers: Maciej Jastrzębski on Twitter / X .
We could implement following rules:
Setting the above rules will require updating 7 test files, which can be done along with adding the configuration.
cc @OlimpiaZurek
The text was updated successfully, but these errors were encountered: