React Component Tests for Humans with Miroslav Nikolov - RRU 242
Jan 3, 2024
auto_awesome
UI developer Miroslav Nikolov discusses his approach to unit testing React components using the UnexpectedJS library. He also talks about his blog built with Gatsby and Mailchimp, and emphasizes the importance of understanding context before criticizing others online. The podcast also covers topics like writing human-friendly tests, the evolution of web development, and global state management in React applications.
Unexpected JS is a testing framework that enables developers to write human-friendly tests with plain English syntax, making them easy to read.
The choice of testing style should be based on what works best for the specific situation, team, and organization, with different approaches and tools suiting different contexts.
Deep dives
The Benefits of Using Unexpected JS for React Component Testing
Miraslav Niklov discusses the advantages of using Unexpected JS, a library he has been using for the past five years to write human-friendly react component tests. The library allows for plain English syntax when writing tests, making them easy to read. While it may not be a popular choice, Unexpected JS offers unique features and has gained attention due to its strong presence on Cessus tricks. Miraslav highlights that testing styles differ, and what works for one organization may not work for another.
Understanding Unexpected JS: A Testing Framework Worth Exploring
Unexpected JS is a testing framework that may not be widely known, but Miraslav provides an introduction to its features. He explains that Unexpected JS can work in conjunction with other testing libraries like React Testing Library, enabling developers to write plain English tests with custom assertions. While there are varying opinions on testing styles, Miraslav emphasizes that the choice should be based on what works best for the specific situation and team.
Creating Human-Friendly React Component Tests with Unexpected JS
Miraslav discusses the approach of writing human-friendly and easily readable tests using the Arrange-Act-Assert pattern. Unexpected JS allows developers to use plain strings as arguments in the expect assertion function, providing a more English-like syntax. While it may be less convenient for autocompleting function calls, this expressiveness benefits teams collaborating on testing files. The focus is often on testing elements' presence and function execution, rather than comparing DOM structures.
Avoiding Dogmatism: Finding What Works for Your Testing Needs
Miraslav acknowledges that testing approaches and tools can be a controversial topic, and opinions can become dogmatic. He emphasizes the importance of selecting the testing style that suits an individual situation, team, and organization. Some developers may discourage certain practices, such as using dumb comparisons or testing function calls, but the effectiveness of these methods depends on the context. Miraslav encourages developers to think critically and choose what works best for them.
On this episode of React Round Up we chatted with Miroslav Nikolov, a UI developer at one.com, about his approach to unit testing React components. Miroslav discussed writing components in a human-friendly way, using the library UnexpectedJS. We also talked about Miroslav’s blog, including how he got started with it, and some of the tools he used, like Gatsby and Mailchimp. This is a great episode if you’re looking to learn more about how to approach unit testing in React. Sponsors