"Неожиданный токен <" Использование теста "npm" с vue -раскрытиями и Vue + jest - PullRequest
1 голос
/ 27 февраля 2020

Я получаю сообщение об ошибке от jest "SyntaxError: Неожиданный токен <" </p>

Jest test error

Вот мой тест в файле spec.js.

import { shallowMount, createLocalVue } from '@vue/test-utils'
import promotionsForm from '@/components/promotions/PromotionsForm.vue'
import router from '@/router';

const localVue = createLocalVue();

jest.mock('@/store')
jest.mock('@/helpers', () => {
   return {
       startDate: jest.fn().mockReturnValue(
         new Date(Date.now())
       ),
       Helper: {
         getCountryCurrencyCode () {
           return 'USD'
         }
       }
   }
})


describe('promotionsForm.vue', () => {
  it('Past dates should be disabled', () => {
      const wrapper = shallowMount(promotionsForm, {localVue, router})
      expect(wrapper.find('.date-inline-picker:first-child input').exists()).toBe(true)
  })
})

Вот мои jest.config.js настройки

 module.exports = {
  moduleFileExtensions: ['js', 'json', 'vue', 'html'],
  transform: {
    '^.+\\.vue$': 'vue-jest',
    '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    '^.+\\.js$': 'babel-jest',
    '^.+\\.html?$': 'html-loader-jest'
  },
  transformIgnorePatterns: [
    '/node_modules/'
  ],
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1'
  },
  snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
  setupFiles: ['<rootDir>/test/unit/setup'],
  testMatch: ['**/test/unit/**/*.spec.js'],
  coverageDirectory: '<rootDir>/test/unit/coverage',
  collectCoverageFrom: [
    'src/**/*.{js,vue}',
    '!src/main.js',
    '!src/router/index.js',
    '!**/node_modules/**'
  ]
 }

Что я пропускаю или делаю неправильно?

1 Ответ

1 голос
/ 28 февраля 2020

Проблема, как мне кажется, в том, что babel не настроен на преобразование ваших vue файлов.

Не видя настройки Трудно сделать конкретные c предложения, но я бы порекомендовал вам go хотя документы здесь: https://vue-test-utils.vuejs.org/guides/testing-single-file-components-with-jest.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...