Why Is Front-end Testing So Damn Hard?

in technology •  7 years ago 

As a front-end developer some of the biggest challenges I face are not programming related nor are they related to combatting Internet Explorer or weird web browser bugs, the biggest challenge I face as a front-end developer is the tooling.

Never mind that a new magical bundler or task tool appears every five minutes that is allegedly faster and built for modern web applications.

Time and time again, testing is where it all falls apart. And you might be inclined to argue that maybe it's just me and I am misunderstanding or screwing something up.

The reality is, I do consulting/contract work helping companies with their front-end architectures and processes, the testing is the one aspect that universally many developers/companies struggle with.

There are a few choices out there, but ultimately you will settle on either Karma + Jasmine or Jest. These are the two options you will highly likely use.

In the case of Jest, it's a great testing solution and is really easy to set up. The downside is Jest is not designed to run your code in real browsers, it's a Node.js based testing solution and as such, you have no real DOM or ability to test actual code support for features in browsers.

Karma is a great test runner and has numerous plugins, works with Jasmine, Mocha and all of those test writing languages. The downside to Karma is it is so damn difficult to set up. If you can get by on using community created plugins and they've been kept up-to-date, you are fine.

In my case right now, I am currently trying to get Karma working with Webpack 4, TypeScript and Jasmine. A relatively simple setup, I have followed the guides and cannot get the code to run. The error messages are super unhelpful and can lead you astray because of the way stack traces work, sometimes the real error is buried.

Why does it have to be this way?

When you want flexibility, you make a sacrifice. You can't assume anything, so you need to create a super basic base tool and then allow the community to build on top of it. All well and good if you can get the community building plugins (great), but the hard part is getting the community to maintain and keep them updated.

In my situation, it turns out the latest version of Webpack and Karma (using karma-webpack) has some unsupported issues, so for now, I have to downgrade and use an older version. This is something I discovered whilst desperately trying to solve the problem.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!