Kurs Google
Kurs Google

Reputation: 309

Error while trying to run scripts: regeneratorRuntime is not defined

I have problem to run a test in mocha and chai. I am getting an error:

Error while trying to run scripts: regeneratorRuntime is not defined

and 500 status internal error.

I've thought it's some kind of a problem with babel configuration and tested functionalities manually and it's working.

package.json:

json


     "scripts": {
            "test": "./node_modules/.bin/mocha --require @babel/register --recursive './test/**/*.spec.js'"
          }

.babelrc:

json

    {
      "presets": [
        "@babel/preset-env"
      ]
    }

test:

javascript
import chai from "chai";
import server from "../../index";
import chaiHttp from "chai-http";
const { expect } = chai;

chai.use(chaiHttp);

function validResponse(err, res, status) {
  expect(err).to.be.null;
  expect(res).to.have.status(status);
  expect(res).to.be.json;
}

describe("get one page of recipe", function() {

  it("should return page with recipe", function(done) {
    chai
      .request(server)
      .get("/api/recipe/page/1")
      .end((err, res) => {
        validResponse(err, res, 200);
        console.log(res.body)
        expect(res.body).to.be.an("object");
        done();
      });
  });
});

Upvotes: 2

Views: 367

Answers (1)

Ramaraja
Ramaraja

Reputation: 2626

This is likely because you are using a feature that's not supported properly by the Babel presets configured.

Try installing babel-polyfill,

npm i -D babel-polyfill

And then include it in your startup file,

import 'babel-polyfill';

Upvotes: 2

Related Questions