DEV Community

Randall
Randall

Posted on

Does anyone else hate Jest?

I'm usually not this full of hatred, I promise, but lately I've realized that I really hate Jest.

Whenever I have a choice, I use Mocha for new projects, and find it a breeze to use.

As far as I can tell, the root cause of my hatred is Jest's custom module loader, causing my modules to get loaded in a completely different way when running under Jest compared to running under ts-node or node. This leads to many scenarios where if I configure my project a certain way, I have to go and configure Jest in some different, non-obvious way, often involving installing Jest plugins, leading to a giant, un-updatable dependency tree of plugins. Or sometimes I just can't get it to work, period.

One lasting problem, and maybe it's fixed by now (I've long since given up), is that it's somewhere between very hard and impossible to use ES modules with Jest, especially if you've got TypeScript in the mix too. Just can't make it work. Even the Stackoverflow gods didn't have a solution.

So now I've got a CJS project with Jest. That's fine I guess. Until I want to use an NPM module that only supports ESM. But I can use dynamic import, right? Wrong. Works fine when I run my code with ts-node, but Jest chokes on it and can't load the module. Once again even the great Stackoverflow gods can't help me. I swear nothing brings me groveling to their altar as often as Jest does. And all for naught.

With Mocha, I remember it wasn't super simple at the beginning, but with some effort I was able to crack the code, so-to-speak. I have a project template with Mocha that supports ES modules just fine. Supports the VS Code debugger just fine. Supports TypeScript just fine no matter how I configure it. I haven't been able to achieve hardly any of that with Jest.

I realize Jest has some cool features like parallelism, but I've rarely if ever had a Node.js project that benefited from them. I know it has a lot built in for testing React and other frontend code as well, maybe it's great for that, I've never used it for that purpose, so I am simply ignorant there.

I'll end my rant there. Has anyone else had similar struggles? Have you cracked the code with Jest? If so, please, show me!

Top comments (2)

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

On a large React project, my team wound up dropping Jest after realizing we were spending twice as long making the test framework function as we were actually writing code and real tests.

Collapse
 
fyodorio profile image
Fyodor

In terms of parallelism you mentioned Jest is not ideal as well, at least in monorepo context, had problems with that 90% of the time