1

I am learning React+Redux now and came to the testing section. Many people use Mocha or Jest to test React components, so far so good, makes sense.

I previously have experience using Selenium and I see that Mocha is quite different in a sense that it tests just small parts of a web page(ReactComponents) and not the whole page. So in my understanding testing in Mocha is something like 'unit test' for components rather than long functional test with user stories and user behavior.

Considering testing a big project - does it make sense to use Selenium together with Mocha, even to the extent of almost copy-pasting tests? On a first glance we do something different with Selenium - i.e. we use the real browser, but on the other hand if we tested every possible thing in Mocha it should in theory be 'ALL PASSED' situation if tested in Selenium anyway, isn't it? So is it redundant to use both and should I just stick to one?

2
  • Do you mean "Is it worth having both end-to-end tests and unit tests for my front end application"?
    – Nathan
    Commented Oct 16, 2016 at 16:40
  • @NathanCooper, not exatly, for example we can check in Mocha that certain elements are rendered on the page. But we can do the same thing in Selenium without even knowing what frameworks behind it(like a real user). Of course tests specific to React should be unit tests with something like Mocha, but the visual part can be done in either of those two. I can drop Selenium and do everything in Mocha, but I am not sure if that will make problems later. Commented Oct 16, 2016 at 16:46

1 Answer 1

2

I am going to answer my own question since it dawned on me kinda. Note this is my way of thinking when dealing specifically with React.

So when writing tests in Mocha we are mostly doing only unit tests, sure we test the proper rendering of individual component, we can even test returned ajax data, but writing integration tests in Mocha lot harder than in Selenium. Moreover, Selenium is easily picked up by QA workers unlike Mocha(since Mocha is more about white-box testing).

I would say that the testing can be split in such a way:

  • Test individual components rendering in Mocha, but don't go too deep(for example don't test CSS).
  • Write functional tests in Selenium and test more high-level things like CSS.
  • All the rest front-end unit tests are in Mocha of course.

The reasoning being is that it is much more easier to get real example of page showed to user in Selenium, in Mocha it will be additional hassle to be sure that proper css is loaded for example. Component rendering tests in Mocha can be useful if it is heavily reusable component, so if you would use only Selenium you would need to do multiple tests probably.

Not sure if that is a common practice, but that reasoning sounds right to me, feel free to correct me.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.