Rich
Rich

Reputation: 1051

preferred testing methods for ReactJS?

Having just scoped our first serious React with NodeJs project we're re-evaluating our testing processes. FYI we're traditionally we're an Angular based agency running a Jasmine/Karma etc setup taking out first - excited - steps into ReactJS.

We've had several approaches suggested, generally a Mocha framework based with JsDOM combined with Chai / Mockery / ShouldJS etc.

But newer players of which we've no experience have been suggested like Tape, Jest

Then there's the upcoming Shallow Rendering feature which sounds great but is it stable and usuable with current limitations - is anyone using it yet? there was an interesting read on another thread earlier this year.

Do people generally still use Selenium for React projects or stick with what they can do inside Mocha or are there preferred alternatives? This topic alone seems to have almost marmite advise.

I realise that there are multiple testing routes and 'right tools' for the job, especially when considering things like:

So any community insight and experience input into preferred flows would be much appreciated!

Upvotes: 0

Views: 172

Answers (1)

Tom
Tom

Reputation: 2611

We've been using jasmine/karma with mocha reporting perfectly fine with React. We found jest to be slow even with a small number of tests.

With React's TestUtils, you can easily test event simulation, e.g.

TestUtils.Simulation.click(element, eventObj);

Testing component state is as easy as:

expect(component.state.myValue).toBe("hello");

Setup isn't that much different as you would with Angular.

Upvotes: 1

Related Questions