2

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

2
  • It should work fine, react-testing-library is just a DOM testing framework and it's decoupled from jest or any other framework. The examples show jest because it's what the majority of the React community uses. Commented Feb 13, 2019 at 12:30
  • thanks for your quick answer. I'll just go ahead and use it. Commented Feb 13, 2019 at 12:31

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, very informative. I'll have a look at jasmine/rewire mocking capabilities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.