How to find the root cause of a failing test if Jest doesn’t tell you what’s wrong

Debugging tests can be hard — but it doesn’t need to be

Ali Kamalizade
3 min readJan 29, 2021
Photo by Sigmund on Unsplash

Writing tests can feel slow and mundane. Testing frameworks like Jest are often making our lives as developers easier through a great developer experience. I’ve been using Jest in both frontend applications (e.g. with Angular) and in Node.js based services (e.g. Express.js) for quite a while.

Recently, one Angular project was updated and required developers to use Node 14 from now on (previously, the project required Node 10). The update went through smoothly and we didn’t encounter any issues in this process. However, I increasingly noticed an issue that I found rather strange. If an uncaught exception occurred in a test case Jest seemed to be stuck and not progress any further no matter how long I’d wait. The error message always looked like this and didn’t tell me much:

UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON

Initially, I didn’t think too much of it. By checking each test case one by one I usually found the root cause. After a few more times, I became curious where this new behaviour came from, though. A simple online search revealed that I wasn’t the only one affected. The issue seems to…

--

--

Ali Kamalizade

Co-founder of Sunhat. Posts about software engineering, startups and anything else. 有難うございます。🚀