小编Eug*_*ene的帖子

Jest 不使用“vue-test-utils”在 Vue 2.7 + TS + Vuetify 上安装合成 API 组件

我正在尝试对composition-api 组件运行单元测试。我使用的是带有 TS 的 Vue 2.7 和以下软件包:

"nuxt": "^2.15.8",
"@nuxtjs/composition-api": "^0.33.1",
"@vue/test-utils": "^1.3.0",
"jest": "^28.1.3",
Run Code Online (Sandbox Code Playgroud)

问题是组件安装时抛出以下错误:

    SyntaxError: Unexpected token (1:1141)

      at Parser.pp$4.raise (node_modules/vue-template-es2015-compiler/buble.js:2757:13)
      at Parser.pp.unexpected (node_modules/vue-template-es2015-compiler/buble.js:647:8)
      at Parser.pp$3.parseExprAtom (node_modules/vue-template-es2015-compiler/buble.js:2196:10)
      at Parser.<anonymous> (node_modules/vue-template-es2015-compiler/buble.js:6003:24)
      at Parser.parseExprAtom (node_modules/vue-template-es2015-compiler/buble.js:6129:31)
      at Parser.pp$3.parseExprSubscripts (node_modules/vue-template-es2015-compiler/buble.js:2047:19)
      at Parser.pp$3.parseMaybeUnary (node_modules/vue-template-es2015-compiler/buble.js:2024:17)
      at Parser.pp$3.parseExprOps (node_modules/vue-template-es2015-compiler/buble.js:1966:19)
      at Parser.pp$3.parseMaybeConditional (node_modules/vue-template-es2015-compiler/buble.js:1949:19)
      at Parser.pp$3.parseMaybeAssign (node_modules/vue-template-es2015-compiler/buble.js:1925:19)
Run Code Online (Sandbox Code Playgroud)

测试示例:

import { mount, createLocalVue } from '@vue/test-utils';
import CompositionApi from '@nuxtjs/composition-api';
import CustomSelect from '@/components/shared/CustomSelect';
import Vuetify from 'vuetify';

const localVue = createLocalVue();
localVue.use(CompositionApi);

let vuetify;

beforeEach(() => { …
Run Code Online (Sandbox Code Playgroud)

vue.js babel-jest vuetify.js vue-test-utils vue-composition-api

7
推荐指数
0
解决办法
814
查看次数