我正在使用这种方法使用 Webpacker (要求我导入 vue.esm.js)。我想按照测试 vuex 文档中的描述测试我的 vuex 突变。它在我使用import Vue from 'vue
' 时有效,但在我使用import Vue from 'vue/dist/vue.esm'
. 但是,如果我不在商店中使用 vue.esm,我的 Webpacker Vue 应用程序就会中断。
这是我的商店:
// store.js
import Vue from 'vue/dist/vue.esm' // changing this to import from 'vue' works
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
count: 0
}
// export `mutations` as a named export
export const mutations = {
increment: state => state.count++
}
export default new Vuex.Store({
state,
mutations
})
这是我的测试:
import { mutations } from './store'
// destructure assign `mutations`
const { increment } = mutations
describe('mutations', () => {
it('INCREMENT', () => {
// mock state
const state = { count: 0 }
// apply mutation
increment(state)
// assert result
expect(state.count).toBe(1)
})
})
上述测试输出:
FAIL app/javascript/test/unit/specs/mutations.spec.js
● Test suite failed to run
myproject/node_modules/vue/dist/vue.esm.js:10671
export default Vue$3;
^^^^^^
SyntaxError: Unexpected token export
我究竟做错了什么?