无法执行Mocha测试,因为返回值超出了功能范围?

时间:2018-12-28 19:45:19

标签: ecmascript-6 mocha chai

我一直在尝试为我的vuex突变设置摩卡/柴测试。但是,我收到一条错误消息:

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;

我的mutation.js文件是:

const setEditedItemIndex = (state, newIndex) => {
    state.editedIndex = newIndex;
};

export default {
    setEditedItemIndex
}

我的mutation.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'

我已经尝试过本comment中记录的解决方案,但这不起作用,下一个解决方案似乎指向只读项目。

0 个答案:

没有答案