【问题标题】:Nuxt/Jest - Syntax Error: Unexpected token {Nuxt/Jest - 语法错误:意外的令牌 {
【发布时间】:2021-10-25 18:26:46
【问题描述】:

我已经安装了 Vue 测试工具,安装了 Jest 并有一个测试用例来验证 vue 实例是否有效。

我的测试如下所示

/* global describe, test, expect */
/* eslint no-undef: "error" */
import { mount } from '@vue/test-utils';
import Logo from '@/components/Logo';

describe('Logo', ()=> {
test('is a vue instance', () => {
const wrapper = mount(Logo)
expect(wrapper.vm).toBeTruthy()
});
});

我使用npm run test 运行它并得到以下错误

import { mount } from '@vue/test-utils'
Syntax error: Unexpected token {

(with an carrot pointing to the { in front of { mount }

有什么想法吗?

***** 编辑添加我的 jest.config.js ****

module.exports = {
  moduleNameMapper: {
   '^@/(.*)$': '<rootDir>/$1',
   '^~/(.*)$': '<rootDir>/$1',
   '^vue$': 'vue/dist/vue.common.js'
 }, 
 moduleFileExtentions: ['js', 'vue', 'json'],
 testPathIgnorePatterns: ['/dist/', '/node_modules/'], 
 transform: {
   '^.+\\.js$' : 'babel-jest',
   '.*\\.(vue)$' : 'vue-jest'
 }, 
collectCoverage: true, 
collectCoverageFrom: [
  '<rootDir>/components/**/*.vue', 
   '<rootDir>/pages/**/*.vue'
 ]
}

【问题讨论】:

  • 你能从你的 package.json 中发布脚本“test”吗?
  • 确定只是“测试”:“开玩笑”
  • 试试:"test": "vue-cli-service test:unit"
  • 我编辑添加我的 jest.config.js 上面运行该命令给了我 sh: vue-cli-service: command not found 如果我在做 NuxtJs,我需要添加什么吗?跨度>

标签: vue.js jestjs nuxt.js vue-test-utils


【解决方案1】:

我发现了这个问题。我需要在我的 babel.config 中将“@babel/preset-env”添加到我的预设中

我现在收到与 Vuetify 相关的错误,但这个问题解决了问题。我将为其他问题创建一个新问题。

【讨论】:

    猜你喜欢
    • 2019-06-20
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    相关资源
    最近更新 更多