Ecmascript 6 无法运行Mocha测试,因为Return在函数之外?
我一直在尝试为我的vuex突变设置mocha/chai测试。然而,我得到一个错误,说:Ecmascript 6 无法运行Mocha测试,因为Return在函数之外?,ecmascript-6,mocha.js,chai,Ecmascript 6,Mocha.js,Chai,我一直在尝试为我的vuex突变设置mocha/chai测试。然而,我得到一个错误,说: mutations.spec.js: 'return' outside of function (1:20) > 1 | const _f38=exports;return _f38.r((function *(exports,require){"use strict";"main";let mutations;_f38.w("../src/View/store/modules/agenda/mu
mutations.spec.js: 'return' outside of function (1:20)
> 1 | const _f38=exports;return _f38.r((function *(exports,require){"use strict";"main";let mutations;_f38.w("../src/View/store/modules/agenda/mutations",[["mutations",["mutations"],function(v){mutations=v}]]);let expect;_f38.w("chai",[["expect",["expect"],function(v){expect=v}]]);yield;
我的.js文件是:
const setEditedItemIndex = (state, newIndex) => {
state.editedIndex = newIndex;
};
export default {
setEditedItemIndex
}
我的translations.spec.js文件是
import { mutations } from '../src/View/store/modules/agenda/mutations';
import { expect } from 'chai';
describe('mutations', () => {
it ('should change the edited item index', () => {
const state = { editedIndex: -1 };
mutations.setEditedItemIndex(state, 1);
expect(state.editedIndex).to.equal(1);
})
})
我正在运行的命令是
./node_modules/mocha/bin/mocha -r esm -r @babel/register './test/**/*.spec.js'
我已经尝试了本文中描述的解决方案,但这不起作用,下一个解决方案似乎指向一个只读项目 在大楼的某个地方,管道传输不知怎么出了问题。您是否尝试过在expect之前添加
return
?