TheSoul
TheSoul

Reputation: 5356

Using react-testing-library and Jasmine

I am playing around with react-testing-library and see whether we should use it in our project. We use jasmine instead of jest. I am wondering is react-testing-library can be easily be used with jasmine (it should be ok...)

Most of the examples I see around are with jest. Are there any caveats in using react-testing-library with jasmine? Are there some examples?

Thank you

Upvotes: 2

Views: 1606

Answers (1)

Estus Flask
Estus Flask

Reputation: 222603

The problem with using react-testing-library with Jasmine or other alternatives is that react-testing-library renders components closely to how they would behave in a browser. Unlike Enzyme, react-testing-library doesn't provide functionality for isolated and fine-grained tests like shallow rendering and accessing component internals like props.

It's expected that all components that shouldn't be rendered as is should be mocked (here's Jest example), react-testing-library doesn't provide any functionality for it, a way they are mocked are at the discretion of a developer. Jasmine doesn't provide ways to mock modules and requires to use third-party solutions like rewire. Jest provides the functionality for module mocking, including babel-jest transform to hoist module mocks when they are used with import.

react-testing-library uses DOM. It's expected that JSDOM should be used if a test runs in Node. Jest natively sets up JSDOM, while a developer needs to set it up manually with Jasmine. It's preferable to run tests in Node rather than in a browser because this way modules can be dynamically mocked due to how Node require works.

Upvotes: 2

Related Questions