Integration test with Cypress or React Testing Library?
Asked Answered
K

2

6

I'm new to testing and as I understand, integration tests are aimed to test a bunch of components and how they interact with each other.

But if in a project we use both Cypress for E2E and React testing library for unit testing, which one to use for integration tests, and what are the pros and cons?

Kasandrakasevich answered 29/11, 2020 at 17:36 Comment(3)
Some argue that testing with RTL is closer to integration than unit tests, depending on what you do with them. Less important than having each "type" of test is that all your tests together show your application working well.Mini
Related #59163138Unvoice
Does this answer your question? What is the difference between using `react-testing-library` and `cypress`?Gammy
I
6

I would recommend using React testing library (RTL) since integration testing is more granular and does not require the entire application to run.

The main benefit of Cypress is that it tests against real browsers which makes it great for ensuring your E2E flows work as intended. While Cypress is fast, it has to do a lot of additional work compared to RTL. I do think Cypress is best for just E2E testing, specifically the high value paths in your application.

Impersonality answered 29/11, 2020 at 19:15 Comment(0)
T
5

Cypress recently introduced component testing, https://docs.cypress.io/guides/component-testing/introduction

Running test in the browser environment makes it easier to understand what's going on within the test thanks to visual feedback from the browser.

Such approach also allows to tests things like drag and drop, which is difficult to achieve with JSDom.

Tarpeia answered 16/11, 2021 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.