Testing React Applications Using React Testing Library
Tran, Mai (2023)
Tran, Mai
2023
All rights reserved. This publication is copyrighted. You may download, display and print it for Your own personal use. Commercial use is prohibited.
Julkaisun pysyvä osoite on
https://urn.fi/URN:NBN:fi:amk-202304145317
https://urn.fi/URN:NBN:fi:amk-202304145317
Tiivistelmä
Testing has become an essential step in software development. Testing verifies that the application will work as expected and avoids unexpected bugs that might occur when some components change. With React applications, the principle is the same. Developers need to write tests that best replicate the user’s interactions with the web application, to find possible defects that will crash the whole application. As the creator of React Testing Library, Kent C.Dodds, stated, “The more your tests resemble how your software is used, the more confidence they can give you.”
This bachelor’s thesis aims to study the testing library recommended by the official React team for React applications – React Testing Library: why it should be used and what are the best practices. Related concepts were studied as part of the purpose to help understand software testing in React thoroughly. The benefits and drawbacks of the library were analyzed by comparing React Testing Library with Enzyme Testing Library. The Enzyme library has been the most common testing library used for React applications. However, with the new version of React, ReactJS 18, the Enzyme library is no longer supported. For the practical part of the research, an application was built for demonstration purposes. Finally, the best practices for the testing library were reviewed based on development and research experience.
The observations and results from this thesis will help developers understand unit testing in React applications and how to use React Testing Library for it. By understanding the testing library thoroughly, they will be able to structure tests and define test cases better, improving the application quality and reducing the time needed to check for errors and bugs
This bachelor’s thesis aims to study the testing library recommended by the official React team for React applications – React Testing Library: why it should be used and what are the best practices. Related concepts were studied as part of the purpose to help understand software testing in React thoroughly. The benefits and drawbacks of the library were analyzed by comparing React Testing Library with Enzyme Testing Library. The Enzyme library has been the most common testing library used for React applications. However, with the new version of React, ReactJS 18, the Enzyme library is no longer supported. For the practical part of the research, an application was built for demonstration purposes. Finally, the best practices for the testing library were reviewed based on development and research experience.
The observations and results from this thesis will help developers understand unit testing in React applications and how to use React Testing Library for it. By understanding the testing library thoroughly, they will be able to structure tests and define test cases better, improving the application quality and reducing the time needed to check for errors and bugs