Soham Nakhare
Soham Nakhare

Reputation: 423

Mocha: TypeError: Converting circular structure to JSON

Mocha suddenly is throwing

TypeError: Converting circular structure to JSON

I have done a new setup for executing the test cases. The test cases were running fine till yesterday. I am using: Mocha, Chai, Sinon, Enzyme

This is my package.json:

{
      "name": "abc",
      "version": "1.0.0",
      "description": "desc",
      "scripts": {
        "build": "webpack --config webpack-client.config.js",
        "devbuild": "webpack --config webpack-client-dev.config.js",
        "test": "mocha --compilers js:babel-register --require ./test/dom.js --require ./test/helpers.js  --recursive",
        "tdd": "npm test -- --watch",
        "coverage": "nyc --reporter=html --reporter=text npm test"
      },
      "repository": {
        "type": "git",
        "url": ""
      },
      "author": "author",
      "license": "ISC",
      "devDependencies": {
        "babel-core": "^6.0.0",
        "babel-loader": "^6.0.0",
        "babel-preset-es2015": "^6.24.1",
        "chai": "^4.0.2",
        "compression-webpack-plugin": "^0.3.2",
        "coveralls": "^2.13.1",
        "enzyme": "^2.9.0",
        "istanbul": "^0.4.5",
        "jquery": "^3.2.1",
        "jsdom": "11.0.0",
        "jsdom-global": "3.0.2",
        "mocha": "3.2.0",
        "nyc": "^11.0.3",
        "react-addons-test-utils": "^15.6.0",
        "sinon": "^2.3.5",
        "webpack": "^1.12.2",
        "webpack-bundle-analyzer": "^2.3.1"
      },
      "dependencies": {
        "exenv": "^1.2.1",
        "expose-loader": "^0.7.0",
        "flux": "2.0.1",
        "html-webpack-plugin": "^2.28.0",
        "htmlescape": "1.0.0",
        "intl": "^1.2.5",
        "intl-locales-supported": "^1.0.0",
        "keymirror": "^0.1.1",
        "morgan": "1.5.2",
        "object-assign": "^4.1.1",
        "prop-types": "^15.5.4",
        "react": "^15.4.2",
        "react-bootstrap": "^0.31.0",
        "react-dom": "^15.4.2",
        "react-intl": "^2.0.0-beta-2",
        "react-toastr": "^2.8.2",
        "zxcvbn": "^4.4.2"
      }
    }

Please find the error thrown on the console : please find the error thrown on the console Please help. Thank you

Upvotes: 1

Views: 1036

Answers (2)

Junior Mayhe
Junior Mayhe

Reputation: 16411

This error TypeError: Converting circular structure to JSON was gone in my case by installing missing dependencies that were not present in a package.json file.

In my scenario, developers were using KafkaJS, Azure Blob Storage, and so on.

So, I had to run this before running mocha tests

npm install @kafkajs/confluent-schema-registry
npm install @azure/storage-blob

After running this package.json and package-lock.json were updated and the mocha tests work.

Upvotes: -1

derpedy-doo
derpedy-doo

Reputation: 3108

I ran into this. Based on googling around, there seem to be many different causes for this. Here's my situation: I'm using mocha with chai and ts-node/register to run TypeScript test files directly (without needing to transpile them myself).

My solution was this:

Add import {describe, it} from 'mocha'; at the top of my TS test files.

I've never had to do this before and I have no idea why I suddenly need to add them now. But it is what it is.

Upvotes: 0

Related Questions