尝试 运行 脚本时出错:未定义 regeneratorRuntime
Error while trying to run scripts: regeneratorRuntime is not defined
我在 运行 mocha 和 chai 中进行测试时遇到问题。我收到一个错误:
Error while trying to run scripts: regeneratorRuntime is not defined
和 500 状态内部错误。
我认为这是 babel 配置和手动测试功能的某种问题,它正在运行。
package.json:
json
"scripts": {
"test": "./node_modules/.bin/mocha --require @babel/register --recursive './test/**/*.spec.js'"
}
.babelrc:
json
{
"presets": [
"@babel/preset-env"
]
}
测试:
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();
});
});
});
这可能是因为您使用的功能未被配置的 Babel 预设正确支持。
尝试安装 babel-polyfill
,
npm i -D babel-polyfill
然后将其包含在您的启动文件中,
import 'babel-polyfill';
我在 运行 mocha 和 chai 中进行测试时遇到问题。我收到一个错误:
Error while trying to run scripts: regeneratorRuntime is not defined
和 500 状态内部错误。
我认为这是 babel 配置和手动测试功能的某种问题,它正在运行。
package.json:
json
"scripts": {
"test": "./node_modules/.bin/mocha --require @babel/register --recursive './test/**/*.spec.js'"
}
.babelrc:
json
{
"presets": [
"@babel/preset-env"
]
}
测试:
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();
});
});
});
这可能是因为您使用的功能未被配置的 Babel 预设正确支持。
尝试安装 babel-polyfill
,
npm i -D babel-polyfill
然后将其包含在您的启动文件中,
import 'babel-polyfill';