UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON with Jest + Angular

Solution 1:

Run jest with --detectOpenHandles. This will show you what is actually wrong with your test spec. For me, there were missing Angular Material imports and service mocks. You may be prompted to add the BrowserAnimationsModule, as Nambi alluded to in his answer

package.json:

"test": "jest --detectOpenHandles"

Solution 2:

This message usually appears, if there is an error, that does not resolve into a standard exception.

As mentioned by @JamesBarret using jests detect open handle feature will provide you with a nice error message, telling you what the real problem behind this message is.

The handle --detectOpenHandles mentioned in the other message is deprecated though and was replaced with --detect-open-handles.

You can just use: (on your cli)

jest --detect-open-handles

Or in a package.json file:

"test": "jest --detect-open-handles"

Or as it was in my case an angular test:

ng test --detect-open-handles

Solution 3:

Adding my answer to help someone if missed. In my case i have missed to import

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

Able to find the issue only when running one of the test case in isolation.