2

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();
      });
  });
});
Vega
  • 27,856
  • 27
  • 95
  • 103
Kurs Google
  • 309
  • 1
  • 11
  • Possible duplicate of [Babel 6 regeneratorRuntime is not defined](https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined) – Håken Lid Jul 26 '19 at 18:03

1 Answers1

2

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';
Ramaraja
  • 2,526
  • 16
  • 21